-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change in behaviour of bun.In with empty slice #902
Comments
Looks like this bug was introduced by 1e624cc. See the change in |
To reproduce:
Add this test case to the end of the func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Where("id IN (?)", bun.In([]int{}))
}, Run the tests (
It will fail because we haven't yet created the testdata snapshots for the new test case, but it will create them. e.g.
Inspect what it created for each DB:
Now switch to the v1.1.13 release and rerun the tests:
Observe that the tests fail because the output has changed since v1.1.12:
|
This also affected me. Any updates? |
Problem
Consider a query using
bun.In
with an empty slice:In bun v1.1.12 it produces this SQL for all dialects:
In bun v1.1.13 and later releases, it produces this SQL for all dialects:
sqlite is the only supported dialect that would accept the
id NOT IN ()
syntax. Changing it toid NOT IN (NULL)
in v1.1.13 means the behaviour has changed from matching all rows to matching no rows. Test usingsqlite3
command line interface:For all other dialects, v1.1.12's
id NOT IN ()
is not valid syntax. e.g. postgres will error with:The new v1.1.13 version with the
NULL
is not a syntax error, but is also not the intended behaviour. You would expect a select of values "not in the empty set" to be "all values", but the use of NULL means no rows match.Proposed solution
The sqlite docs say this about the IN and NOT IN operators:
So it would be reasonable for bun to detect an empty slice being passed to
bun.In
and to error I think. That would give consistent behaviour across all dialects. Even though sqlite is capable of coping with the empty set, bun hasn't been generating such since v1.1.12 anyway.The text was updated successfully, but these errors were encountered: