I create programmatically sql queries to Postgresql like this:
SELECT * FROM table WHERE column IN (1, 2, 3);
SELECT * FROM table WHERE column IN (1);
SELECT * FROM table WHERE column IN ();
The last query generates a syntax error. How should I handle this special case and write an empty array here?
Internally,
col IN (1, 2, 3)
is converted to
col = ANY (ARRAY[1,2,3]::integer[])
That syntax will also work for empty arrays:
col = ANY (ARRAY[]::integer[])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With