-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
allow empty slice for 'in' queries #945
base: master
Are you sure you want to change the base?
Conversation
Why not just check before you execute your query. if len(configIDs) != 0 {
db.Exec("DELETE FROM server_config WHERE server_id = ? AND config_id NOT IN (?)", srvID, configIDs)
} |
if note the |
if len(configIDs) == 0 {
db.Exec("DELETE FROM server_config WHERE server_id = ?", srvID)
} else {
db.Exec("DELETE FROM server_config WHERE server_id = ? AND config_id NOT IN (?)", srvID, configIDs)
} |
I mean, of course - but why make things complicated? especially when there are multiple such parameters that would lead to unnecessarily complicated repetition and nested if statements. I don't see any benefit to keeping this check. |
Have you tried running your query manually with an empty If you tried that it would give you an error. Empty But even if SQL did support that syntax, the size of the table and the access frequency could affect performance and cost. From a performance and cost perspective, its best to do the simple calculation in the app instead of having the DB do it; but even still, SQL doesn't like empty sets in that clause which is why that check is there. |
Empty But even otherwise, for this app there will never be any amount of data where a full table scan would slow anything down whatsoever. I've been using my patch without problems for my usecase for 2 weeks now. SQLFiddle: https://sqlfiddle.com/sqlite/online-compiler?&id=5ad24c05-77a0-43d9-92d4-2d2ad520f9a0 |
What's the benefit of returning the error early vs letting the DB engine decide if it wants to allow empty |
Most SQL databases consider this syntax invalid and will raise an error; your PR cannot be merged in. If your local branch with your changes works for you that's perfect. |
I'm sorry but I still don't understand the benefit of the check. Either the error gets raised here or ot gets raised when the DB is queried - what's the harm in raising it later? Also why does it matter how many DBs support this? What would we do if it was 50/50? Toss a coin? |
I suppose one reason I can see is that it would be a breaking change and it's risky if it only helps for SQLite, which is fair enough. |
Can be useful for queries like below.