Skip to content

Commit

Permalink
sql: disallow UDF in SET DEFAULT and SET ON UPDATE
Browse files Browse the repository at this point in the history
Release note (sql change): previously users were able to sneak
in UDF usage from tables with `SET DEFAULT` and `SET ON UPDATE`
even they are disallowed from `CREATE TABLE` and `ADD COLUMN`.
This patch disallows those two cases from `ALTER TABLE ALTER COLUMN`.
  • Loading branch information
chengxiong-ruan committed Feb 21, 2023
1 parent 154712a commit f8f969f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ func sanitizeColumnExpression(
return nil, "", pgerror.WithCandidateCode(err, pgcode.DatatypeMismatch)
}

if err := funcdesc.MaybeFailOnUDFUsage(typedExpr, context, p.EvalContext().Settings.Version.ActiveVersionOrEmpty(p.ctx)); err != nil {
return nil, "", err
}
s := tree.Serialize(typedExpr)
return typedExpr, s, nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ ALTER TABLE test_tbl_t ADD COLUMN c int DEFAULT (test_tbl_f());
statement error pq: unimplemented: usage of user-defined function from relations not supported
ALTER TABLE test_tbl_t ADD COLUMN c int ON UPDATE (test_tbl_f());

statement error pq: unimplemented: usage of user-defined function from relations not supported
ALTER TABLE test_tbl_t ALTER COLUMN b SET DEFAULT (test_tbl_f());

statement error pq: unimplemented: usage of user-defined function from relations not supported
ALTER TABLE test_tbl_t ALTER COLUMN b SET ON UPDATE (test_tbl_f());

subtest disallow_udf_in_views_and_udf

statement ok
Expand Down

0 comments on commit f8f969f

Please sign in to comment.