Skip to content

Commit

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

release-24.3: sql/schemachanger: handle empty schemas gracefully
  • Loading branch information
fqazi authored Nov 22, 2024
2 parents a915efc + 572a17b commit 3bd733b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
Expand Up @@ -1481,3 +1481,24 @@ SELECT qux();
NULL

subtest end

subtest empty_schema_name

user root

statement ok
set role root;
use defaultdb;

skipif config local-legacy-schema-changer
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 @@ -1907,8 +1907,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 3bd733b

Please sign in to comment.