Skip to content

Treat Dates, Buffers and typed parameters in sql([...]) as values, not rows - #1326

Merged
porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/values-list-of-dates
Nov 20, 2026
Merged

porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/values-list-of-dates

Conversation

@efeesrefinal

Copy link
Copy Markdown
Contributor

values() (used by sql([...]) in in and values lists) treats the list as rows when its first element is any object, and takes the columns from Object.keys of that element. A Date, a Buffer or a sql.typed() parameter is an object too, so:

sql`select 1 where x in ${ sql([d]) }`                  // in (null), no parameter: matches nothing
sql`select 1 where x in ${ sql([d1, d2]) }`             // in (),(): syntax error
sql`select 1 where x in ${ sql([Buffer.from('ab')]) }`  // in ($1,$2) with [97, 98]
sql`select 1 where x in ${ sql([sql.typed(5, 23)]) }`   // in ($1,$2) with [5, 23]

The first and the last two return wrong rows without an error. These elements are now treated as single values, so the lists become in ($1) / in ($1,$2) as with numbers and strings. Arrays and other objects are still rows.

Tests: four cases in tests/unit/build.cases.js. They fail on master with the output above and pass with this change; node tests/unit passes (180). Against Postgres 16, select $1::timestamptz in ${ sql([d]) } returned null on master and true with this change, and the two-date list went from a syntax error to true. I didn't run the integration suite.

@porsager
porsager merged commit bdc7c6d into porsager:master Nov 20, 2026
71 of 74 checks passed
@porsager

Copy link
Copy Markdown
Owner

Thanks! Good catch, and nice fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants