Parameterized Queries
This feature was introduced in Hydrolix version 5.11.
Prevent SQL injection and make query templates reusable by using parameterized queries. This practice separates SQL logic from data values. Instead of interpolating values directly into SQL strings, define {name:Type} placeholders in the query and pass values as param_-prefixed HTTP parameters. Hydrolix substitutes the values as typed literals before execution.
Parameterized queries work on both the HTTP Query API (/query) and the ClickHouse HTTP interface (port 8088).
Usage⚓︎
Define {name:Type} placeholders in the SQL query. For each placeholder, include a corresponding param_name=value HTTP parameter. Hydrolix strips the param_ prefix, matches the remaining name to the placeholder, validates the value against the declared type, and substitutes it as a literal value.
The Type in the placeholder is any ClickHouse data type like UInt64, String, Date, DateTime, or DateTime64(3).
Parameters can appear in the URL query string, the POST body, or both. When the same parameter name appears in both locations, POST body values overwrite URL values.
GET examples⚓︎
Use --data-urlencode with -G to pass param_ parameters in the URL query string.
| Parameterized Query with GET | |
|---|---|
Alternatively, pass everything directly in the URL.
| Parameterized Query with GET (Inline URL) | |
|---|---|
POST examples⚓︎
Pass param_ parameters in the URL query string and the SQL as the POST body.
| Parameters in URL, Query in Body | |
|---|---|
Alternatively, pass both the parameters and the query in the POST body using --data-urlencode.
Combine parameters with query options⚓︎
Parameterized query values (param_-prefixed) and query options (such as hdx_query_debug or max_execution_time) don't interfere with each other. Include both in the same request.
| Parameters and Query Options Together | |
|---|---|
Error handling⚓︎
If a query contains a {name:Type} placeholder but the corresponding param_name parameter is missing, the query returns a ClickHouse error:
| Missing Parameter Error | |
|---|---|
If the supplied value doesn't match the declared type, ClickHouse returns a type conversion error.