diff --git a/pkg/sql/logictest/testdata/logic_test/srfs b/pkg/sql/logictest/testdata/logic_test/srfs index 00d75035c9de..7fd790ba9341 100644 --- a/pkg/sql/logictest/testdata/logic_test/srfs +++ b/pkg/sql/logictest/testdata/logic_test/srfs @@ -1422,3 +1422,47 @@ NULL NULL 4 5 + +# Regression test for #110952 - providing invalid arguments to unnest should +# not trigger an internal error. +statement error pgcode 42804 pq: could not determine polymorphic type: unnest\(string\) +SELECT unnest('{}'); + +statement error pgcode 42804 pq: could not determine polymorphic type: unnest\(string, string, string\) +SELECT unnest('{}', '{}', '{}'); + +statement error pgcode 42883 pq: unknown signature: unnest\(int\) +SELECT unnest(1); + +statement error pgcode 42883 pq: unknown signature: unnest\(int, int, int\) +SELECT unnest(1, 2, 3); + +statement error pgcode 42804 pq: could not determine polymorphic type: unnest\(unknown\) +SELECT unnest(NULL); + +statement error pgcode 42804 pq: could not determine polymorphic type: unnest\(unknown, unknown, unknown\) +SELECT unnest(NULL, NULL, NULL); + +# pg_expandarray handles return types similarly to unnest. +statement error pgcode 42804 pq: could not determine polymorphic type: information_schema._pg_expandarray\(string\) +SELECT information_schema._pg_expandarray('{}'); + +query T +SELECT unnest('{1}'::int[], '{2}', '{3}'); +---- +(1,2,3) + +query T +SELECT unnest('{1}'::int[], '{}', '{}'); +---- +(1,,) + +query T +SELECT unnest('{1}', '{2}', '{3}'::int[]); +---- +(1,2,3) + +query T +SELECT unnest('{}', '{}', '{3}'::int[]); +---- +(,,3) diff --git a/pkg/sql/sem/builtins/generator_builtins.go b/pkg/sql/sem/builtins/generator_builtins.go index 0477eedb7bbe..11f088d61ce3 100644 --- a/pkg/sql/sem/builtins/generator_builtins.go +++ b/pkg/sql/sem/builtins/generator_builtins.go @@ -299,7 +299,7 @@ var generators = map[string]builtinDefinition{ makeGeneratorOverloadWithReturnType( tree.ParamTypes{{Name: "input", Typ: types.AnyArray}}, func(args []tree.TypedExpr) *types.T { - if len(args) == 0 || args[0].ResolvedType().Family() == types.UnknownFamily { + if len(args) == 0 || args[0].ResolvedType().Family() != types.ArrayFamily { return tree.UnknownReturnType } return args[0].ResolvedType().ArrayContents() @@ -319,7 +319,7 @@ var generators = map[string]builtinDefinition{ returnTypes := make([]*types.T, len(args)) labels := make([]string, len(args)) for i, arg := range args { - if arg.ResolvedType().Family() == types.UnknownFamily { + if arg.ResolvedType().Family() != types.ArrayFamily { return tree.UnknownReturnType } returnTypes[i] = arg.ResolvedType().ArrayContents() @@ -337,7 +337,7 @@ var generators = map[string]builtinDefinition{ makeGeneratorOverloadWithReturnType( tree.ParamTypes{{Name: "input", Typ: types.AnyArray}}, func(args []tree.TypedExpr) *types.T { - if len(args) == 0 || args[0].ResolvedType().Family() == types.UnknownFamily { + if len(args) == 0 || args[0].ResolvedType().Family() != types.ArrayFamily { return tree.UnknownReturnType } t := args[0].ResolvedType().ArrayContents()