Error 42: NUMBER_OF_ARGUMENTS_DOESNT_MATCH
подсказка
This error occurs when you call a ClickHouse function with the wrong number of arguments.
The function expects a specific number of parameters, but you provided either too many or too few.
Most common causes
-
Incorrect function signature
- Passing individual values instead of arrays (e.g.,
multiSearchAny)
- Missing required arguments
- Providing too many arguments
- Not understanding function overload variants
-
Misunderstanding documentation
- Function documentation unclear or outdated
- Examples showing incorrect usage
- Confusion between similar function names
- Missing information about required vs optional parameters
-
Array functions expecting single array parameter
- Passing multiple string literals instead of array
- Using varargs syntax when function expects array
- For example:
multiSearchAny(haystack, 'a', 'b', 'c') should be multiSearchAny(haystack, ['a', 'b', 'c'])
-
Type conversion functions with wrong parameter count
toFixedString requires 2 arguments (string, length)
toDecimal requires precision and scale
- Timezone functions requiring timezone parameter
- Format functions requiring format string
-
User-defined functions (UDFs) with wrong signature
- Custom functions called with incorrect argument count
- Lambda functions with mismatched parameter count
- Higher-order functions with wrong lambda signature
What to do when you encounter this error
1. Check the error message for function details
The error message tells you exactly what went wrong:
Number of arguments for function multiSearchAny doesn't match: passed 5, should be 2
Number of arguments for function toFixedString doesn't match: passed 1, should be 2
Incorrect number of arguments for function generateSnowflakeID provided 2, expected 0 to 1
2. Look up the function documentation
-- Check function exists and its signature
SELECT * FROM system.functions WHERE name = 'multiSearchAny';
-- Or search for similar functions
SELECT name FROM system.functions WHERE name LIKE '%search%';
3. Review official documentation
Visit ClickHouse functions documentation to verify:
- Required vs optional parameters
- Expected data types
- Usage examples
- Alternative function variants
4. Test with simple example
-- Test function with minimal valid arguments
SELECT multiSearchAny('test string', ['test', 'example']);
-- Check if function works as expected
SELECT toFixedString('hello', 10);
Quick fixes
1. For array functions - wrap arguments in array
-- Instead of this (fails):
SELECT multiSearchAny(text, 'ClickHouse', 'Clickhouse', 'clickHouse');
-- Use this (works):
SELECT multiSearchAny(text, ['ClickHouse', 'Clickhouse', 'clickHouse']);
2. For type conversion functions - provide all required parameters
-- Instead of this (fails):
SELECT toFixedString(15);
-- Use this (works):
SELECT toFixedString('15', 10); -- string value, length
-- For decimals:
SELECT toDecimal64(123.45, 2); -- value, scale
3. For functions with optional parameters - check ranges
-- Function may accept variable argument counts
SELECT generateSnowflakeID(); -- 0 arguments (OK)
SELECT generateSnowflakeID(expr); -- 1 argument (OK)
-- SELECT generateSnowflakeID(expr1, expr2); -- 2 arguments (ERROR)
4. Use correct function variant
-- Different functions for different purposes:
-- For single needle in haystack:
SELECT position('haystack', 'needle');
-- For multiple needles (requires array):
SELECT multiSearchAny('haystack', ['needle1', 'needle2']);
-- For first position of any needle:
SELECT multiSearchFirstPosition('haystack', ['needle1', 'needle2']);
5. Check for renamed or deprecated functions
-- Some functions have been renamed or changed signatures
-- Check release notes if migrating between versions
-- Use SHOW FUNCTIONS or system.functions to find correct name
SELECT name, origin FROM system.functions WHERE name LIKE '%YourFunction%';
Common specific scenarios
Scenario 1: multiSearchAny with multiple string literals
Number of arguments for function multiSearchAny doesn't match: passed 5, should be 2
Cause: multiSearchAny expects 2 arguments: haystack and an array of needles. User passed multiple individual string arguments.
Solution:
-- Instead of this (fails):
SELECT multiSearchAny(text, 'ClickHouse', 'Clickhouse', 'clickHouse', 'clickhouse');
-- Use this (works - wrap in array):
SELECT multiSearchAny(text, ['ClickHouse', 'Clickhouse', 'clickHouse', 'clickhouse']);
-- Example with column:
SELECT
body,
multiSearchAny(body, ['error', 'warning', 'critical']) AS has_alert_keyword
FROM logs;
Reference: Slack Internal Discussion
Scenario 2: toFixedString with missing length parameter
Number of arguments for function toFixedString doesn't match: passed 1, should be 2
Cause: toFixedString requires both the string value and the fixed length.
Solution:
-- Instead of this (fails):
SELECT toFixedString(15);
-- Use this (works):
SELECT toFixedString('15', 2); -- String value, fixed length
-- With column:
SELECT toFixedString(user_id, 36) AS fixed_user_id
FROM users;
-- Pad with zeros:
SELECT toFixedString(toString(id), 10) AS padded_id
FROM table;
Reference: GitHub Issue #61024
Scenario 3: generateSnowflakeID with too many arguments
Incorrect number of arguments for function generateSnowflakeID provided 2 (UInt8, DateTime64(3)), expected 0 to 1
Cause: generateSnowflakeID accepts 0 or 1 argument, but 2 were provided.
Solution:
-- Valid usages:
SELECT generateSnowflakeID(); -- No arguments
SELECT generateSnowflakeID(1); -- With expression
-- Instead of this (fails):
SELECT generateSnowflakeID(1, now64(3));
-- Use this (works):
SELECT generateSnowflakeID();
-- Or
SELECT generateSnowflakeID(toUInt8(1));
Reference: Slack Internal Discussion
Scenario 4: parseDateTime with wrong argument count
Number of arguments for function parseDateTime doesn't match
Cause: Missing format string parameter or providing too many arguments.
Solution:
-- parseDateTime requires 2-3 arguments: string, format, [timezone]
-- Instead of this (fails):
SELECT parseDateTime('2024-01-15');
-- Use this (works):
SELECT parseDateTime('2024-01-15', '%Y-%m-%d');
-- With timezone:
SELECT parseDateTime('2024-01-15 10:30:00', '%Y-%m-%d %H:%M:%S', 'America/New_York');
-- Or use best effort parsing (1-2 arguments):
SELECT parseDateTimeBestEffort('2024-01-15');
SELECT parseDateTimeBestEffort('2024-01-15', 'Europe/London');
Scenario 5: Array distance functions with wrong types
Arguments of function arrayL2Distance have different array sizes: 0 and 1536
Cause: While this appears as error 190 (SIZES_OF_ARRAYS_DONT_MATCH), it's often caused by empty arrays or NULL values that should be filtered.
Solution:
-- Filter out empty arrays before calculation
SELECT
id,
L2Distance(embedding1, embedding2) AS distance
FROM table
WHERE notEmpty(embedding1)
AND notEmpty(embedding2);
-- Or use ifNull to provide defaults
SELECT
id,
L2Distance(
ifNull(embedding1, arrayWithConstant(1536, 0.0)),
ifNull(embedding2, arrayWithConstant(1536, 0.0))
) AS distance
FROM table;
Prevention best practices
-
Always check function documentation first
-
Use system.functions table
-- Find function and its description
SELECT
name,
origin,
description
FROM system.functions
WHERE name = 'yourFunction';
-- Search for similar functions
SELECT name
FROM system.functions
WHERE name ILIKE '%search%'
ORDER BY name;
-
Test functions with simple examples
-- Test with literal values first
SELECT multiSearchAny('test', ['t', 'e']);
-- Then apply to your data
SELECT multiSearchAny(column, ['value1', 'value2'])
FROM your_table;
-
Pay attention to function naming patterns
- Functions ending in
Any: usually take arrays
- Functions with
First, Last, All: variants with different return types
- Functions with
OrNull, OrZero: safe variants that handle errors
-
Watch for version differences
-- Check ClickHouse version
SELECT version();
-- Some functions change signatures between versions
-- Check release notes when upgrading
-
Use IDE or CLI autocomplete
- ClickHouse CLI shows function signatures
- IDEs with ClickHouse support show parameter hints
- Helps avoid argument count mistakes
Common function signatures
String search functions:
-- Single needle
position(haystack, needle)
positionCaseInsensitive(haystack, needle)
-- Multiple needles (array required!)
multiSearchAny(haystack, [needle1, needle2, ...])
multiSearchFirstPosition(haystack, [needle1, needle2, ...])
multiSearchAllPositions(haystack, [needle1, needle2, ...])
Type conversion functions:
-- Fixed length strings
toFixedString(string, length)
-- Decimals
toDecimal32(value, scale)
toDecimal64(value, scale)
toDecimal128(value, scale)
-- Dates
toDate(value)
toDateTime(value)
toDateTime(value, timezone)
toDateTime64(value, precision)
toDateTime64(value, precision, timezone)
Date/time parsing:
-- Flexible parsing
parseDateTimeBestEffort(string)
parseDateTimeBestEffort(string, timezone)
-- Strict parsing
parseDateTime(string, format)
parseDateTime(string, format, timezone)
parseDateTimeInJodaSyntax(string, format)
Aggregate functions:
-- Basic
sum(column)
avg(column)
count()
-- With conditions
sumIf(column, condition)
avgIf(column, condition)
countIf(condition)