ClickHouse / ClickHouse/ClickHouse

Add support for expression parameters when call querying a parametrized view

Open
#87,904 0 comments 1 reaction 0 assignees View on GitHub
comp-view external feature
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

When querying a parametrized view, it seems only primitive values are accepted:

```sql
select *
from events(from=1759211015000, to=1759237515000)
limit 5
```

This query fails:

```sql
select *
from events(from=1759211015000 + 1, to=1759237515000)
limit 5
```

```text
error querying the database: code: 456, message: Substitution `from` is not set
```

This query fails too (same error):

```sql
select *
from events(from=toUnixTimestamp('2025-01-01 01:01:01')*1000, to=1759237515000)
limit 5
```

### Use case

This seems a pretty logical things to support. One use case I can think of is Grafana, which exposes `$__from` and `$__to` variables, which can't be manipulated when used in parametrized query parameters.

Yet one valid use case is week-over-week comparison, which would require writing something like this:

```sql
select *
from events(from=addDays($__fromTime, -7), to=$__toTime)
```

### Describe the solution you'd like

Add support for expression in parametrized query parameters.

### Describe alternatives you've considered

Creating a "fake" query variable in Grafana with value `SELECT $__from - 7 * 24 *3600 * 1000`

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.