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.

IN() query statement not possible with parameters

See original GitHub issue

The following query throws an error:

con.query(`SELECT * FROM BDDIVE#DAT.BDKSTP WHERE kstp.KSKST IN (?)`, [[4434, 4438]])

It throws the error [odbc] Error binding parameters

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tibbingcommented, Jun 7, 2022

Would like to upvote this. Queries like

query(
  `SELECT id, number FROM employees WHERE number IN ?`,
   [managerNumbers]
)

works in libraries like mysql/mysql2, mssql etc. The workaround suggested, joining the values to a string does at least not seem to work with a Databricks database.

Using multiple question marks (IN (?, ?...)) works, but is not very clean when you have a dynamic number of values - you’d have to generate the number of questions marks n times, so the query is no longer a constant string.

0reactions
forstiecommented, Jul 7, 2022

It took a bot to spur me into action. Whomever owns this query() function could map the values to the appropriate number of question marks in the IN list. Further, OPEN USING SUBSET could be used to such that there’s always 1000 or whatever entries in the IN list, but on each usage, the actual number of IN list entries are identified. That would bridge functional behavior and performance.

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 >
Using Parameters for SQL Server Queries and Stored ...
In this tip we look at different ways to parameterize a SQL Server query.
Read more >
Execute SQL Task - SQL Server Integration Services (SSIS)
Use the Parameter Mapping page of the Execute SQL Task Editor dialog box to map variables to parameters in the SQL statement. Options....
Read more >
Passing parameters to SQL queries - Psycopg
Passing parameters to a SQL statement happens in functions such as Cursor.execute() by using %s placeholders in the SQL statement, and passing a...
Read more >
Working with parameters in the sp_executesql stored procedure
This article will show how to use the sp_executesql system stored procedure to run static and dynamic SQL queries.
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