Skip to content

Commit

Permalink
Add dynamic query params example (#16964)
Browse files Browse the repository at this point in the history
Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com>
  • Loading branch information
writer-jill and vtlim committed Aug 27, 2024
1 parent 21dcf80 commit 3e031b9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/querying/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ at execution time. To use dynamic parameters, replace any literal in the query w
corresponding parameter value when you execute the query. Parameters are bound to the placeholders in the order in
which they are passed. Parameters are supported in both the [HTTP POST](../api-reference/sql-api.md) and [JDBC](../api-reference/sql-jdbc.md) APIs.

Druid supports double and null values in arrays for dynamic queries.
The following example query uses the [ARRAY_CONTAINS](./sql-functions.md#array_contains) function to return `doubleArrayColumn` when the reference array `[-25.7, null, 36.85]` contains all elements of the value of `doubleArrayColumn`:

```sql
{
"query": "SELECT doubleArrayColumn from druid.table where ARRAY_CONTAINS(?, doubleArrayColumn)",
"parameters": [
{
"type": "ARRAY",
"value": [-25.7, null, 36.85]
}
]
}
```

In certain cases, using dynamic parameters in expressions can cause type inference issues which cause your query to fail, for example:

```sql
Expand Down Expand Up @@ -435,4 +450,4 @@ To use the reserved keywords in queries, enclose them in double quotation marks.

```sql
SELECT "PARTITIONED" from druid.table
```
```

0 comments on commit 3e031b9

Please sign in to comment.