diff --git a/internal/function.go b/internal/function.go index 355a2aa..99e527e 100644 --- a/internal/function.go +++ b/internal/function.go @@ -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 diff --git a/query_test.go b/query_test.go index ec27ddc..fb12529 100644 --- a/query_test.go +++ b/query_test.go @@ -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)`,