I have found many Questions and Answers about a SELECT excluding rows with a value "NOT IN" a sub-query (such as this). But how to exclude a list of values rather than a sub-query?
I want to search for rows whose timestamp is within a range but exclude some specific date-times. In English, that would be:
Select all the ORDER rows recorded between noon and 2 PM today except for the ones of these times: Today 12:34, Today 12:55, and Today 13:05.
SQL might be something like:
SELECT * FROM order_ WHERE recorded_ >= ? AND recorded_ < ? AND recorded_ NOT IN ( list of date-times… ) ; So two parts to this Question:
- How to write the SQL to exclude rows having any of a list of values?
- How to set an arbitrary number of arguments to a
PreparedStatementin JDBC?
(the arbitrary number being the count of the list of values to be excluded)
recorded_ <> ALL( ? ), with a param of typetimestamp[]. Not sure how to feed this in via JDBC, though.NOT INis effectively the same as<> ALL(): stackoverflow.com/a/31192557/939860. The problem with both: they fail if NULL is involved on either side of the expression. The expression evaluates to NULL; but only TRUE passes aWHEREcondition: stackoverflow.com/a/19528722/939860NOT IN (...)is equivalent to<> ALL (ARRAY[...]). You can create an array in JDBC withcreateArrayOf, then pass that as a parameter.