From a8c595dda5418ad6f392aae2f953db7409f89ffc Mon Sep 17 00:00:00 2001 From: Drew Kimball Date: Thu, 25 Apr 2024 23:46:22 +0000 Subject: [PATCH] sql: link to issue for DDL inside of routines This commit adds an issue link to the "unsupported" error message when a user attempts to use a DDL statement from within a routine. Informs #110080 Release note: None --- pkg/sql/logictest/testdata/logic_test/udf_unsupported | 6 +++--- pkg/sql/opt/optbuilder/builder.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/udf_unsupported b/pkg/sql/logictest/testdata/logic_test/udf_unsupported index ee26eef0970e..a2f95fdcd20e 100644 --- a/pkg/sql/logictest/testdata/logic_test/udf_unsupported +++ b/pkg/sql/logictest/testdata/logic_test/udf_unsupported @@ -92,13 +92,13 @@ subtest end subtest ddl # DDL is not currently supported in UDF bodies. -statement error pgcode 0A000 unimplemented: CREATE TABLE usage inside a function definition +statement error pgcode 0A000 unimplemented: CREATE TABLE usage inside a function definition.*\n.*\n.*issue-v/110080 CREATE FUNCTION err() RETURNS VOID LANGUAGE SQL AS 'CREATE TABLE t (a INT)' -statement error pgcode 0A000 unimplemented: ALTER TABLE usage inside a function definition +statement error pgcode 0A000 unimplemented: ALTER TABLE usage inside a function definition.*\n.*\n.*issue-v/110080 CREATE FUNCTION err() RETURNS VOID LANGUAGE SQL AS 'ALTER TABLE t ADD COLUMN b BOOL' -statement error pgcode 0A000 unimplemented: DROP TABLE usage inside a function definition +statement error pgcode 0A000 unimplemented: DROP TABLE usage inside a function definition.*\n.*\n.*issue-v/110080 CREATE FUNCTION err() RETURNS VOID LANGUAGE SQL AS 'DROP TABLE t' subtest end diff --git a/pkg/sql/opt/optbuilder/builder.go b/pkg/sql/opt/optbuilder/builder.go index 48cd383d2461..9723483773a9 100644 --- a/pkg/sql/opt/optbuilder/builder.go +++ b/pkg/sql/opt/optbuilder/builder.go @@ -369,6 +369,11 @@ func (b *Builder) buildStmt( panic(doBlockVersionErr) } default: + if tree.CanModifySchema(stmt) { + panic(unimplemented.NewWithIssuef(110080, + "%s usage inside a function definition is not supported", stmt.StatementTag(), + )) + } panic(unimplemented.Newf("user-defined functions", "%s usage inside a function definition", stmt.StatementTag())) } }