From e5bdadf94ecc55cadcd0c7708beab68c7236e026 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Sat, 17 Oct 2026 00:53:56 -0400 Subject: [PATCH v1] Qualify unqualified names in CREATE SCHEMA elements again Commit a9c350d9e stopped filling in the new schema's name, and the revert in 962e0a723 kept that. So an index or trigger could land on a temp table of the same name, and a view could quietly become a temp view. Fill in the name as v18 did, on a copy of the elements. --- src/backend/parser/parse_utilcmd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index f0c7755b8fb..a6167e2f7bb 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -4169,6 +4169,9 @@ transformCreateSchemaStmtElements(ParseState *pstate, List *schemaElts, cxt.grants = NIL; cxt.foreign_keys = NIL; + /* We fill in schema names below, so work on a copy */ + schemaElts = copyObject(schemaElts); + /* * Run through each schema element in the schema element list. Check * target schema names, separate statements by type, and do preliminary @@ -4264,17 +4267,17 @@ transformCreateSchemaStmtElements(ParseState *pstate, List *schemaElts, * Check schema name in an element of a CREATE SCHEMA command, * where the element's name is given by a RangeVar * - * It's okay if the command doesn't specify a target schema name, because - * CreateSchemaCommand will set up the default creation schema to be the - * new schema. But if a target schema name is given, it had better match. + * If the command doesn't specify a target schema name, fill in the new + * schema's name. But if a target schema name is given, it had better match. * We also have to check that the command doesn't say CREATE TEMP, since * that would likewise put the object into the wrong schema. */ static void checkSchemaNameRV(CreateSchemaStmtContext *cxt, RangeVar *relation) { - if (relation->schemaname != NULL && - strcmp(cxt->schemaname, relation->schemaname) != 0) + if (relation->schemaname == NULL) + relation->schemaname = pstrdup(cxt->schemaname); + else if (strcmp(cxt->schemaname, relation->schemaname) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_SCHEMA_DEFINITION), errmsg("CREATE specifies a schema (%s) " -- 2.37.1 (Apple Git-137.1)