-
-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Use Case
ClickHouse natively supports Query Parameters feature [1][2], which allow users to write generic SQL templates using typed placeholders. This avoids manual string interpolation, improves readability, and reduces the risk of SQL injection.
Sample usage
import chdb
df = chdb.query(
"SELECT toDate({base_date:String}) + number AS date "
"FROM numbers({total_days:UInt64}) "
"LIMIT {items_per_page:UInt64}",
"DataFrame",
params={"base_date": "2025-01-01", "total_days": 10, "items_per_page": 2},
)
print(df)
# expected output:
# date
# 0 2025-01-01
# 1 2025-01-02This is standard ClickHouse syntax, but chdb does not yet support passing query parameters.
Describe the solution you'd like
Enable query parameters in chdb by wiring through ClickHouse’s native setQueryParameters C++ API.
Expose this capability across chdb’s language bindings (Python, Node.js, etc.) so end users can easily supply a params dictionary when executing a query.
Additional context
This would bring chdb to parity with clickhouse client CLI and clickhouse-connect Python library
- ClickHouse client CLI supports this feature [2], e.g.
clickhouse-client --param_message='hello' --query="SELECT {message: String}"
hello- clickhouse-connect, the official ClickHouse Python client library, supports similar features in its
QueryContextAPI [3]
client.create_query_context(query='SELECT value1, value2 FROM data_table WHERE key = {k:Int32}',
parameters={'k': 2},
column_oriented=True)
result = client.query(context=qc)References
[1] ClickHouse SQL syntax: defining and using query parameters, https://clickhouse.com/docs/sql-reference/syntax#defining-and-using-query-parameters
[2] How to Use Query Parameters in ClickHouse, https://clickhouse.com/videos/how-to-use-query-parameters-in-clickhouse
[3] clickhouse-connect client library's support for query parameters, https://clickhouse.com/docs/integrations/language-clients/python/advanced-querying#querycontexts