Skip to content
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

calling where_in with an empty array returns all rows #49

Open
Flamenco opened this issue Oct 20, 2018 · 4 comments
Open

calling where_in with an empty array returns all rows #49

Flamenco opened this issue Oct 20, 2018 · 4 comments
Labels

Comments

@Flamenco
Copy link

qb.where_in('id',[])
qb.get(...)

This results in all rows returned, instead of no rows returned.

@kylefarris
Copy link
Owner

Personally, I think that is the appropriate result for this case. When an invalid or empty list is provided, it should probably be ignored.

@Flamenco
Copy link
Author

Flamenco commented Feb 1, 2019

When one query returns the empty array, it is not appropriate to return all rows in a second query. This should mirror the behavior of a select where foo in (select ...). or a join

I end up having to micro-manage every time I use the result set of queries by checking if they are empty.

Please reconsider.

@kylefarris
Copy link
Owner

Sorry man, this is a query builder not something that's going to cover every edge case. Really, it should probably throw an error since that's what writing a query like this: SELECT * FROM foo WHERE id in () would do. I chose to take the route of assuming it was a mistake and gracefully ignoring the clause.

If you want it to work like a join or a sub-query, you should probably write it as such. Otherwise, as a general practice for all programming (not just this module), I would suggest checking the outcome of previous queries before using those results in something else. If you don't do that in general, you going to have a lot of surprises in your program.

@Flamenco
Copy link
Author

Flamenco commented Feb 1, 2019

The correct generated SQL should be:

SELECT * FROM foo WHERE false

IMO your query-builder should not return an error when it is a conclusion that no results can be returned. It should return an empty resultset. Certainly not all rows. This is not an edge case issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants