Skip to content

Commit

Permalink
Merge pull request cockroachdb#129275 from cockroachdb/blathers/backp…
Browse files Browse the repository at this point in the history
…ort-release-24.2-129179

release-24.2: sql: don't allow VOID parameters for UDFs
  • Loading branch information
rafiss authored Aug 20, 2024
2 parents 343453c + 1ec2c7d commit 8ebb267
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_params
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ CREATE FUNCTION f(OUT param INT) RETURNS VOID AS $$ SELECT 1; $$ LANGUAGE SQL;
statement error pgcode 42P13 pq: function result type must be int because of OUT parameters
CREATE FUNCTION f(OUT param INT) RETURNS RECORD AS $$ SELECT 1; $$ LANGUAGE SQL;

statement error pgcode 42P13 SQL functions cannot have arguments of type VOID
CREATE FUNCTION f(param VOID) RETURNS UUID LANGUAGE SQL AS $$ SELECT NULL $$;

statement ok
CREATE FUNCTION f(OUT param INT) RETURNS INT AS $$ SELECT 1; $$ LANGUAGE SQL;

Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/opt/optbuilder/create_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,13 @@ func (b *Builder) buildCreateFunction(cf *tree.CreateRoutine, inScope *scope) (o
if param.Class == tree.RoutineParamInOut && param.Name == "" {
panic(unimplemented.NewWithIssue(121251, "unnamed INOUT parameters are not yet supported"))
}
if param.IsInParam() && typ.IsPolymorphicType() {
sawPolymorphicInParam = true
if param.IsInParam() {
if typ.Family() == types.VoidFamily {
panic(pgerror.Newf(pgcode.InvalidFunctionDefinition, "SQL functions cannot have arguments of type VOID"))
}
if typ.IsPolymorphicType() {
sawPolymorphicInParam = true
}
}
if param.IsOutParam() {
outParamTypes = append(outParamTypes, typ)
Expand Down
3 changes: 2 additions & 1 deletion pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3960,7 +3960,8 @@ FROM
if typeVal.Identical(types.AnyTuple) ||
typeVal.IsWildcardType() ||
typeVal == types.RegClass ||
typeVal.Family() == types.OidFamily {
typeVal.Family() == types.OidFamily ||
typeVal.Family() == types.VoidFamily {
continue
}
if pgVectorNotSupported && typeVal.Family() == types.PGVectorFamily {
Expand Down

0 comments on commit 8ebb267

Please sign in to comment.