Open
Description
The sql call below returns an empty array to the rows variable. I'm not sure how the query is being translated exactly (is there a way to see the generated query?) but I think throwing would be more useful than gracefully returning an empty array.
const arr = []
const rows = await sql`select *
from generate_series(1, 5) i
where i not in ${sql(arr)};`
await sql.end()
console.log(rows)```
Activity
mattbishop commentedon Nov 26, 2022
Postgres gives a syntax error if you try to run SELECT IN with an empty array:
RyanDurk commentedon Nov 26, 2022
Just to clarify, postgres does. Postgresjs does not, and instead returns an empty array for that query. Which is the issue.
porsager commentedon Jan 3, 2023
Hi @RyanDurk .. Yeah, it might be a bit too magical that Postgres.js sends
(null)
if the array is empty. It's something to consider changing with v4 since it's breaking. I'm not sure if it should go, or if the behaviour should simply be documented better. What do you think?sk-shishi commentedon Jan 7, 2023
The behavior is even more surprising with bulk inserts. It just hangs when the array is empty.
porsager commentedon Jan 7, 2023
@sk-shishi that sounds like a different issue. Could you post more details?