diff --git a/pkg/sql/opt/exec/execbuilder/testdata/sql_fn b/pkg/sql/opt/exec/execbuilder/testdata/sql_fn index 4fed1985d067..a303661672aa 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/sql_fn +++ b/pkg/sql/opt/exec/execbuilder/testdata/sql_fn @@ -241,3 +241,10 @@ CREATE TABLE my_spatial_table ( CONSTRAINT "primary" PRIMARY KEY (k ASC), FAMILY "primary" (k, geom1, geom2, geom3, geom4, geom5, geom6, geom8, geom9, geom10) ) + +# Regression test for #50296. Using AddGeometryColumn with NULL arguments must +# not panic. +query T +SELECT addgeometrycolumn('a', 'b', 3, NULL, 2); +---- +NULL diff --git a/pkg/sql/opt/optbuilder/scope.go b/pkg/sql/opt/optbuilder/scope.go index 09dd5d180880..226a54c4ab2e 100644 --- a/pkg/sql/opt/optbuilder/scope.go +++ b/pkg/sql/opt/optbuilder/scope.go @@ -1255,6 +1255,9 @@ func (s *scope) replaceSQLFn(f *tree.FuncExpr, def *tree.FunctionDefinition) tre if err != nil { panic(err) } + if typedFunc == tree.DNull { + return tree.DNull + } f = typedFunc.(*tree.FuncExpr) args := make(memo.ScalarListExpr, len(f.Exprs))