In(..) clause with empty collection has no affect #516

Closed
opened 2017-01-06 01:07:44 +00:00 by ethantkoenig · 3 comments
ethantkoenig commented 2017-01-06 01:07:44 +00:00 (Migrated from github.com)

If I do something like engine.In("my_column", []int64{}).Find(&results), every row of the corresponding table will be returned (just like engine.Find(&results)). I would instead expect no rows to be returned, since a SQL query with an empty IN clause, such as SELECT * FROM foo WHERE col in (SELECT 0 WHERE 0=1) returns no rows.

If this is a bug, I would be happy to fix it.

If I do something like `engine.In("my_column", []int64{}).Find(&results)`, every row of the corresponding table will be returned (just like `engine.Find(&results)`). I would instead expect no rows to be returned, since a SQL query with an empty `IN` clause, such as `SELECT * FROM foo WHERE col in (SELECT 0 WHERE 0=1)` returns no rows. If this is a bug, I would be happy to fix it.

Yes, I know this. Keep it no condition or a false condition for empty In which one is better?

Yes, I know this. Keep it no condition or a false condition for empty `In` which one is better?
ethantkoenig commented 2017-01-06 02:01:35 +00:00 (Migrated from github.com)

I personally prefer false condition; I think that is the behavior that most users would expect.

I personally prefer false condition; I think that is the behavior that most users would expect.
localvar commented 2017-02-07 02:19:21 +00:00 (Migrated from github.com)

agree with @ethantkoenig , false condition make sense.

the 2nd parameter of In (the array) may be generated by program code, in this case, if keep current behavior, I have to write code like below:

if len(arr) == 0 {
    // process empty result
} else {
   // normal processing
}

but if make it false condition, client side code could be simplified to exclude if & else.

agree with @ethantkoenig , false condition make sense. the 2nd parameter of `In` (the array) may be generated by program code, in this case, if keep current behavior, I have to write code like below: ```go if len(arr) == 0 { // process empty result } else { // normal processing } ``` but if make it false condition, client side code could be simplified to exclude `if` & `else`.
lunny referenced this issue from a commit 2020-03-09 02:52:44 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#516
No description provided.