question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameterized SQL queries with IN keyword

See original GitHub issue

Are 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
moderakhcommented, Feb 10, 2017

@yvele a workaround to this is to rewrite the query as:

{      
    query: "SELECT * FROM root r WHERE ARRAY_CONTAINS(@bar, r.foo)",     
    parameters: [          
        { name: "@bar", value: ["a", "b", "c"] }       
    ] 
}
2reactions
vathakurcommented, Aug 8, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found