Skip to content

Commit

Permalink
Fix IN() operator return when left-hand side is null (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Mar 9, 2024
1 parent 79d9841 commit 3556815
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func BETWEEN(target, start, end Value) (Value, error) {

func IN(a Value, values ...Value) (Value, error) {
if a == nil {
return BoolValue(false), nil
return nil, nil
}
for _, v := range values {
if v == nil {
Expand Down
14 changes: 8 additions & 6 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ func TestQuery(t *testing.T) {
expectedRows: [][]interface{}{{true}},
},
{
name: "in operator",
query: `SELECT 3 IN (1, 2, 3, 4)`,
expectedRows: [][]interface{}{{true}},
name: "in operator",
query: `SELECT 3 IN (1, 2, 3, 4), null IN (1), null IN (null)`,
// When left-hand side is null, null is always returned
expectedRows: [][]interface{}{{true, nil, nil}},
},
{
name: "not in operator",
query: `SELECT 5 NOT IN (1, 2, 3, 4)`,
expectedRows: [][]interface{}{{true}},
name: "not in operator",
query: `SELECT 5 NOT IN (1, 2, 3, 4), null NOT IN (1), null NOT IN (null)`,
// When left-hand side is null, null is always returned
expectedRows: [][]interface{}{{true, nil, nil}},
},
{
name: "is null operator",
Expand Down

0 comments on commit 3556815

Please sign in to comment.