Skip to content

Commit

Permalink
[Functions] Fix NULLIF panic on null (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Mar 9, 2024
1 parent 3556815 commit 6a17ac7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ func IFNULL(expr, nullResult Value) (Value, error) {
}

func NULLIF(expr, exprToMatch Value) (Value, error) {
if expr == nil {
return nil, nil
}
cond, err := expr.EQ(exprToMatch)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ FROM UNNEST([1, 2, 3, 4]) AS val`,
query: `SELECT NULLIF(10, 0)`,
expectedRows: [][]interface{}{{int64(10)}},
},
{
name: "nullif null",
query: `SELECT NULLIF(null, 0)`,
expectedRows: [][]interface{}{{nil}},
},
{
name: "rounding",
query: `SELECT ROUND(2.0), ROUND(2.3), ROUND(2.8), ROUND(2.5), ROUND(-2.3), ROUND(-2.8), ROUND(-2.5)`,
Expand Down

0 comments on commit 6a17ac7

Please sign in to comment.