Repository navigation
fix(postgres): handle null/undefined values in $in/$nin queries - #11152
Merged
ArtyomSavchenko merged 1 commit intoOct 19, 2026
Merged
ArtyomSavchenko merged 1 commit into
ArtyomSavchenko merged 1 commit into
Conversation
A query like { dueDate: { $in: [undefined, null] } } produced invalid SQL
on Postgres/CockroachDB: "data#>>'{dueDate}' = ANY(ARRAY[]::jsonb[])", which
fails with "unsupported comparison operator: <string> = ANY <jsonb[]>".
inferType() only looked at the first two array elements, so an array of
null-ish values was typed as jsonb[], and the $in/$nin branches still
emitted an empty ANY/ALL comparison after the null values were filtered out.
inferType() now uses the first non-null element of an array. $in/$nin
treat undefined like null (as the Mongo adapter does): when only null-ish
values are given they translate to plain IS NULL / IS NOT NULL, otherwise
the remaining values are compared and combined with the null check.
Fixes hcengineering#9697
Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
ArtyomSavchenko
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9697
Problem and change
A query like { dueDate: { $in: [undefined, null] } } produced invalid SQL
on Postgres/CockroachDB: "data#>>'{dueDate}' = ANY(ARRAY[]::jsonb[])", which
fails with "unsupported comparison operator: = ANY <jsonb[]>".
inferType() only looked at the first two array elements, so an array of
null-ish values was typed as jsonb[], and the $in/$nin branches still
emitted an empty ANY/ALL comparison after the null values were filtered out.
inferType() now uses the first non-null element of an array. $in/$nin
treat undefined like null (as the Mongo adapter does): when only null-ish
values are given they translate to plain IS NULL / IS NOT NULL, otherwise
the remaining values are compared and combined with the null check.
Tests
New cases in
foundations/server/packages/postgres/src/__tests__/conversion.spec.tsandutils.spec.ts; they fail without the fix. Checked on a self-hosted CockroachDB-backed instance:$in: [null],$in: [undefined, null],$nin: [null]and mixed lists return the expected issues, and the Due date filters (Today, Not specified, exact date) load without the "unsupported comparison operator" error.