Skip to content

Commit

Permalink
Merge pull request #135926 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-135910

release-24.1: sql/schemachanger: handle empty schemas gracefully
  • Loading branch information
fqazi authored Nov 22, 2024
2 parents bcf534b + e4ed824 commit 59ad8c8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,17 @@ RESET CLUSTER SETTING sql.auth.public_schema_create_privilege.enabled

subtest end


subtest schema_with_temp_in_name

statement ok
CREATE SCHEMA my_pg_temp_123_123;

statement ok
DROP SCHEMA my_pg_temp_123_123;

subtest end

# Regression test for #126244: during Memo staleness checking, check object
# resolution before privileges, to avoid spurious privilege errors.
subtest check_privileges_after_resolution
Expand Down Expand Up @@ -1470,3 +1481,25 @@ SELECT qux();
NULL

subtest end

subtest empty_schema_name

user root

statement ok
set role root;
use defaultdb;

skipif config local-legacy-schema-changer
skipif config local-mixed-23.1
statement error pgcode 42601 pq: empty schema name
CREATE SCHEMA ""."";

onlyif config local-legacy-schema-changer
statement error pgcode 3D000 pq: database \"\" does not exist
CREATE SCHEMA ""."";

statement error pgcode 42601 pq: .*empty schema name
CREATE SCHEMA "";

subtest end
3 changes: 1 addition & 2 deletions pkg/sql/schemachanger/scbuild/builder_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1790,8 +1790,7 @@ func (b *builderState) serializeUserDefinedTypes(

func (b *builderState) ResolveDatabasePrefix(schemaPrefix *tree.ObjectNamePrefix) {
if schemaPrefix.SchemaName == "" || !schemaPrefix.ExplicitSchema {
panic(errors.AssertionFailedf("schema name empty when resolving database prefix for a " +
"schema name"))
panic(pgerror.Newf(pgcode.Syntax, "empty schema name"))
}
if schemaPrefix.CatalogName == "" {
schemaPrefix.CatalogName = tree.Name(b.cr.CurrentDatabase())
Expand Down

0 comments on commit 59ad8c8

Please sign in to comment.