Parameterized SQL queries with IN keyword
See original GitHub issueAre parameterized SQL with IN keyword supposed to be working?
Neither this
{
query: "SELECT * FROM root r WHERE r.foo IN (@bar)",
parameters: [
{ name: "@bar", value: ["a", "b", "c"] }
]
}
or this
{
query: "SELECT * FROM root r WHERE r.foo IN @bar",
parameters: [
{ name: "@bar", value: ["a", "b", "c"] }
]
}
are working… They gives a syntax error.
PS: Parameterized SQL query documentation states that:
Parameter values can be any valid JSON (strings, numbers, Booleans, null, even arrays or nested JSON). Also since DocumentDB is schema-less, parameters are not validated against any type.
Any workaround other than the usual SQL server hack?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Parameterize an SQL IN clause - Stack Overflow
You can parameterize each value, so something like: string[] tags = new string[] { "ruby", "rails", "scruffy", "rubyonrails" }; string cmdText = "SELECT...
Read more >Parameterized Queries | SQL Tutorial Documentation on data ...
Parameters are defined at the beginning of a query using a declare statement. Declare statements start with the keyword DECLARE , followed by...
Read more >Using Parameters for SQL Server Queries and Stored ...
In this tip we look at different ways to parameterize a SQL Server query.
Read more >Parameterized SQL Queries: /Documentation - LabKey Support
LabKey Server lets you add parameters to your SQL queries, using the PARAMETERS keyword. When a user views the query, they will first...
Read more >Parameterize SQL queries - Learn | Hex Technologies
When you pass a variable with more than one value (e.g. a list or array) to a SQL query you use the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yvele a workaround to this is to rewrite the query as:
@bingbing8 ARRAY_CONTAINS works for me. Mistake that I was doing before was to enclose the array in double quotes and values in single quotes like
"['aa448e10-88a7-448a-b385-124d02624ffe', '1fccbe54-6ed0-4c88-87ad-2b10d86d8990', '6082b3bf-c472-4a30-a387-24c18495e6ba']"
However, it works like below["aa448e10-88a7-448a-b385-124d02624ffe", "1fccbe54-6ed0-4c88-87ad-2b10d86d8990", "6082b3bf-c472-4a30-a387-24c18495e6ba"]
. Don’t enclose the complete array in qoutes and use double quotes for values.