---
title: NUMBER_OF_ARGUMENTS_DOESNT_MATCH ClickHouse error
meta:
  description: Learn how to fix the NUMBER_OF_ARGUMENTS_DOESNT_MATCH error in ClickHouse and Tinybird. Understand what causes it and see examples of how to resolve it
---

# NUMBER_OF_ARGUMENTS_DOESNT_MATCH ClickHouse error

{% callout %}
This error usually means you're calling a function with the wrong number of arguments. Check the function documentation to see how many parameters it expects and what types they should be.
{% /callout %}

The `NUMBER_OF_ARGUMENTS_DOESNT_MATCH` error in ClickHouse (and Tinybird) happens when you call a function with an incorrect number of arguments. Functions in ClickHouse have specific signatures that define how many parameters they expect and what types those parameters should be.

## What causes this error

You'll typically see it when:

* Calling a function with too few arguments
* Calling a function with too many arguments
* Using the wrong syntax for function calls
* Missing required parameters
* Using optional parameters incorrectly

## Example errors

```sql {% title="Fails: too few arguments" %}
SELECT replace('hello world')
```

```sql {% title="Fails: too many arguments" %}
SELECT toDate('2023-01-01', 'UTC', 'extra')
```

```sql {% title="Fails: missing required parameter" %}
SELECT formatDateTime(now())
```

```sql {% title="Fails: wrong function syntax" %}
SELECT if(user_id > 10, 'high', 'low', 'unknown')
```

## How to fix it

### Check function documentation

Always verify the function signature before using it:

```sql {% title="Correct: replace with all arguments" %}
SELECT replace('hello world', 'world', 'clickhouse')
```

```sql {% title="Correct: toDate with timezone" %}
SELECT toDate('2023-01-01', 'UTC')
```

### Use proper function syntax

Make sure you're using the correct syntax for each function:

```sql {% title="Correct: formatDateTime with format" %}
SELECT formatDateTime(now(), '%Y-%m-%d %H:%M:%S')
```

```sql {% title="Correct: if with three arguments" %}
SELECT if(user_id > 10, 'high', 'low')
```

## Common patterns and solutions

### String functions

Common string functions and their argument counts:

```sql {% title="substring function" %}
SELECT substring('hello world', 1, 5)  -- 3 arguments: string, start, length (indexing starts at 1)
```

```sql {% title="replace function" %}
SELECT replace('hello world', 'world', 'clickhouse')  -- 3 arguments: string, old, new
```

```sql {% title="concat function" %}
SELECT concat('hello', ' ', 'world')  -- variable number of arguments
```

### Date and time functions

Date functions often require specific formats:

```sql {% title="parseDateTimeBestEffort function" %}
SELECT parseDateTimeBestEffort('2023/01/01', 'UTC')  -- 2 arguments: date string, timezone
```

```sql {% title="toDateTime function" %}
SELECT toDateTime('2023-01-01 12:00:00')  -- 1 argument: datetime string
```

```sql {% title="formatDateTime function" %}
SELECT formatDateTime(now(), '%Y-%m-%d')  -- 2 arguments: datetime, format
```

### Conditional functions

Conditional functions have specific argument requirements:

```sql {% title="if function" %}
SELECT if(condition, true_value, false_value)  -- 3 arguments
```

```sql {% title="multiIf function" %}
SELECT multiIf(
    condition1, value1,
    condition2, value2,
    default_value
)  -- odd number of arguments
```

```sql {% title="greatest function" %}
SELECT greatest(1, 2, 3, 4, 5)  -- variable number of arguments
```

```sql {% title="least function" %}
SELECT least(10, 5, 8, 2)  -- variable number of arguments
```

### Aggregate functions

Aggregate functions can have different argument patterns:

```sql {% title="count function" %}
SELECT count(*)  -- 1 argument: expression or *
```

```sql {% title="sum function" %}
SELECT sum(value)  -- 1 argument: numeric expression
```

```sql {% title="avg function" %}
SELECT avg(value)  -- 1 argument: numeric expression
```

## Advanced solutions

### Using optional parameters

Some functions have optional parameters:

```sql {% title="toDate with optional timezone" %}
SELECT toDate('2023-01-01')  -- without timezone
SELECT toDate('2023-01-01', 'UTC')  -- with timezone
```

### Variable argument functions

Some functions accept variable numbers of arguments:

```sql {% title="concat function" %}
SELECT concat('a', 'b', 'c', 'd')  -- any number of arguments
```

```sql {% title="greatest function" %}
SELECT greatest(1, 2, 3, 4, 5)  -- any number of arguments
```

### Function parameter ordering

{% callout type="caution" %}
ClickHouse doesn't support named parameters. Parameter order matters and must match the function signature exactly.
{% /callout %}

```sql {% title="Correct: parameters in order" %}
SELECT substring('hello world', 1, 5)  -- string, start, length
```

```sql {% title="Wrong: wrong parameter order" %}
SELECT substring(1, 'hello world', 5)  -- This will fail
```

### Window functions

Window functions have specific syntax requirements:

```sql {% title="Correct window function" %}
SELECT user_id,
       ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY timestamp) as row_num
FROM events
```

## Function categories and common signatures

### String manipulation
* `substring(string, start, length)` - Extract substring
* `replace(string, old, new)` - Replace substring
* `concat(string1, string2, ...)` - Concatenate strings
* `trim(string)` - Remove whitespace

### Date and time
* `toDate(string)` - Convert to date
* `toDateTime(string)` - Convert to datetime
* `formatDateTime(datetime, format)` - Format datetime
* `now()` - Current timestamp

### Mathematical
* `abs(number)` - Absolute value
* `round(number, decimals)` - Round number
* `power(base, exponent)` - Raise to power
* `sqrt(number)` - Square root

### Conditional
* `if(condition, true_value, false_value)` - Simple conditional
* `multiIf(condition1, value1, condition2, value2, ...)` - Multiple conditions
* `case when ... then ... else ... end` - CASE statement

## Tinybird-specific notes

In Tinybird, this error often occurs when:

* Using ClickHouse functions in Pipes with wrong argument counts
* Calling custom functions with incorrect parameters
* Using Materialized View functions incorrectly
* Working with JSON extraction functions

To debug in Tinybird:

1. Check the ClickHouse function documentation
2. Use the Query Builder to test function calls
3. Verify function signatures in Pipe nodes
4. Test functions with simple examples first

## See also

* [ClickHouse Functions](/sql-reference/functions)
* [String Functions](/sql-reference/functions/string-functions)
* [Date and Time Functions](/sql-reference/functions/date-time-functions)
* [Common function errors](/sql-reference/clickhouse-errors/UNKNOWN_FUNCTION)
