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

whereIn() with empty array #477

Closed
bblack opened this Issue Sep 11, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@bblack
Contributor

bblack commented Sep 11, 2014

Consider the call:

knex('people').whereIn('name', names)

If names is an empty array, the generated query will have invalid syntax:

select * from "people" where "name" in ()

Can knex support empty arrays for whereIn()? e.g. by generating something like

select * from "people" where false

@tgriesser tgriesser closed this in 5280e6e Oct 1, 2014

@tgriesser

This comment has been minimized.

Owner

tgriesser commented Oct 1, 2014

Added, also added .orWhereIn('name', []) to yield select * from 'people' where true

@runeh

This comment has been minimized.

Contributor

runeh commented Oct 20, 2014

It seems like sqlite doesn't support the "where false" syntax. This query:

db('users').whereIn('id', []);

Worked on my sqlite db in knex 0.6.22, but fails in 0.7.x . The error is:

SQLITE_ERROR: no such column: false

Not sure if I'm reading this right, but doesn't seem to support bools here: https://www.sqlite.org/syntax/expr.html

@tgriesser tgriesser reopened this Oct 20, 2014

runeh added a commit to runeh/knex that referenced this issue Oct 20, 2014

tgriesser added a commit that referenced this issue Feb 25, 2015

Added sqlite3 dialect version of whereRaw/andWhereRaw
* SQLite uses integers, not booleans
* whereIn/whereNotIn with empty array uses a boolean
* Closes #477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment