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

`IN` condition in Postgres #511

Closed
arnau opened this Issue Dec 2, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@arnau

arnau commented Dec 2, 2016

Is there a way to create a query like the one below with the query builder?

SELECT id FROM foo WHERE id NOT IN (1, 3, 5);
@sgrif

This comment has been minimized.

Member

sgrif commented Dec 2, 2016

Looks like I forgot to add NOT IN when I added IN. If you're on PG I'd recommend using .ne(any(array)). I'll add NOT IN for SQLite in the next version though.

@sgrif sgrif added this to the 0.9 milestone Dec 2, 2016

@arnau

This comment has been minimized.

arnau commented Dec 2, 2016

Ah, I didn't realise I could use .ne(any(array)). Thanks!

sgrif added a commit that referenced this issue Dec 2, 2016

Add support for `NOT IN`
I will probably eventually re-implement this with an arbitrary `not`
function, but I didn't want to go there quite yet as I'm not sure if
we'll need to do anything with parenthesis for that.

This will add another case we have to deal with empty arrays for, but I
don't think this will affect the implementation other than requiring an
additional test. What I'm thinking we'll do is have the `In` expression
write out `1=0` when it sees an empty array. With this implementation
it'll be `NOT 1=0`, which is exactly what we want. (In empty set = no
rows, not in empty set = all rows)

Fixes #511

@sgrif sgrif closed this in #512 Dec 2, 2016

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