From ea6620b92c7b2a012e3ae9ad665a3d45a86c146a Mon Sep 17 00:00:00 2001 From: Dan Hansen Date: Tue, 6 Feb 2024 14:37:25 -0800 Subject: [PATCH] [Functions] Fix NULLIF panic on null --- internal/function.go | 3 +++ query_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/internal/function.go b/internal/function.go index 067a81f..2b0ba38 100644 --- a/internal/function.go +++ b/internal/function.go @@ -384,6 +384,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 515595e..bbb8417 100644 --- a/query_test.go +++ b/query_test.go @@ -470,6 +470,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)`,