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.

Is there any support for the SQL IN clause? Database.test() .select("select score from person where name IN (?)") .parameters("FRED", "JOSEPH") // or a list of Strings .getAs(Integer.class) .blockingForEach(System.out::println);

I tried a bunch of different ways and I couldn’t figure how I could possibly make it work.

Thank you in advance for your time!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
davidmotencommented, Nov 30, 2017

You seem to have missed my point. I’ll explain the workaround. I’m not talking about the originally suggested hack which would not work because of protection from sql injection but rather of modifying the sql (not the parameters). Here’s an example.

List<String> list = Lists.newArrayList("FRED","JOSEPH");
String questionMarks =  list
  .stream() 
  .map(x -> "?")
  .collect(Collectors.joining(","));
String sql = "select score from person where name in (" + questionMarks + ");
db.test()
  .select(sql)
  .parameters(list)
  .getAs(Integer.class)
  .blockingForEach(System.out::println);

The full implementation in the api for this will take me a little while (not a quick fix) but would be good to have and with luck I’ll get to it soon but in the meantime you have the above style of workaround.

By the way, many databases have quite low limits for the number of parameters in a sql statement. Oracle used to be about 1000. I think I’ve used 20,000 with H2.

0reactions
davidmotencommented, Dec 6, 2017

Beaut, let me know if more docs needed too

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL IN Operator - W3Schools
CustomerID CustomerName ContactName Address 1 Alfreds Futterkiste Maria Anders Obere Str. 57 2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución... 3 Antonio...
Read more >
SQL: IN Condition
The SQL IN condition (sometimes called the IN operator) allows you to easily test if an expression matches any value in a list...
Read more >
SQL IN Operator - TutorialsTeacher
The IN operator is used to specify the list of values or sub query in the WHERE clause. A sub-query or list of...
Read more >
SQL WHERE IN | NOT IN - Dofactory
WHERE IN returns values that match values in a list. This list is either hardcoded or generated by a subquery. WHERE IN is...
Read more >
Clause in SQL - Types with Syntax and Example - DataFlair
Clauses are in-built functions available to us in SQL. With the help of clauses, we can deal with data easily stored in the...
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