diff --git a/pkg/bench/bench_test.go b/pkg/bench/bench_test.go index 0242f247a3bd..827bcba863ab 100644 --- a/pkg/bench/bench_test.go +++ b/pkg/bench/bench_test.go @@ -1443,8 +1443,7 @@ func BenchmarkFuncExprTypeCheck(b *testing.B) { sqlDB.ExecMultiple(b, `CREATE SCHEMA sc1`, `CREATE SCHEMA sc2`, - // TODO(chengxiong): uncomment this when #97400 is resolved. - //`CREATE FUNCTION abs(val INT) RETURNS INT CALLED ON NULL INPUT LANGUAGE SQL AS $$ SELECT val $$`, + `CREATE FUNCTION abs(val INT) RETURNS INT CALLED ON NULL INPUT LANGUAGE SQL AS $$ SELECT val $$`, `CREATE FUNCTION sc1.udf(val INT) RETURNS INT CALLED ON NULL INPUT LANGUAGE SQL AS $$ SELECT val $$`, `CREATE FUNCTION sc1.udf(val STRING) RETURNS STRING LANGUAGE SQL AS $$ SELECT val $$`, `CREATE FUNCTION sc1.udf(val FLOAT) RETURNS FLOAT LANGUAGE SQL AS $$ SELECT val $$`, @@ -1488,11 +1487,10 @@ func BenchmarkFuncExprTypeCheck(b *testing.B) { name: "builtin aggregate not called on null", exprStr: "concat_agg(NULL)", }, - // TODO(chengxiong): uncomment this when #97400 is resolved. - //{ - // name: "udf same name as builtin", - // exprStr: "abs(123)", - //}, + { + name: "udf same name as builtin", + exprStr: "abs(123)", + }, { name: "udf across different schemas", exprStr: "udf(123)", diff --git a/pkg/sql/logictest/testdata/logic_test/udf b/pkg/sql/logictest/testdata/logic_test/udf index 7e0c62798c8a..1220dbec62c8 100644 --- a/pkg/sql/logictest/testdata/logic_test/udf +++ b/pkg/sql/logictest/testdata/logic_test/udf @@ -3133,3 +3133,22 @@ SELECT f_97130(); statement ok SET search_path = $pre_search_path + +subtest regression_97400 + +# Make sure that creating a UDF with builtin function name is ok. +statement ok +CREATE FUNCTION abs(val INT) RETURNS INT +CALLED ON NULL INPUT +LANGUAGE SQL +AS $$ SELECT val+100 $$; + +query I +SELECT abs(-1) +---- +1 + +query I +SELECT public.abs(-1) +---- +99 diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_function.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_function.go index 6b2795bdb780..77016de2386a 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_function.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_function.go @@ -32,8 +32,13 @@ func CreateFunction(b BuildCtx, n *tree.CreateFunction) { dbElts, scElts := b.ResolvePrefix(n.FuncName.ObjectNamePrefix, privilege.CREATE) _, _, sc := scpb.FindSchema(scElts) _, _, db := scpb.FindDatabase(dbElts) + _, _, scName := scpb.FindNamespace(scElts) + _, _, dbname := scpb.FindNamespace(dbElts) - validateParameters(b, n, db.DatabaseID) + n.FuncName.SchemaName = tree.Name(scName.Name) + n.FuncName.CatalogName = tree.Name(dbname.Name) + + validateParameters(n) existingFn := b.ResolveUDF( &tree.FuncObj{ @@ -142,7 +147,7 @@ func CreateFunction(b BuildCtx, n *tree.CreateFunction) { b.Add(b.WrapFunctionBody(fnID, fnBodyStr, lang, refProvider)) } -func validateParameters(b BuildCtx, n *tree.CreateFunction, parentDBID descpb.ID) { +func validateParameters(n *tree.CreateFunction) { seen := make(map[tree.Name]struct{}) for _, param := range n.Params { if param.Name != "" {