agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't try to re-order the subcommands of CREATE SCHEMA.
Date: Mon, 06 Apr 2026 19:16:37 +0000
Message-ID: <E1w9pR6-003HJO-2d@gemulon.postgresql.org> (raw)

Don't try to re-order the subcommands of CREATE SCHEMA.

transformCreateSchemaStmtElements has always believed that it is
supposed to re-order the subcommands of CREATE SCHEMA into a safe
execution order.  However, it is nowhere near being capable of doing
that correctly.  Nor is there reason to think that it ever will be,
or that that is a well-defined requirement.  (The SQL standard does
say that it should be possible to do foreign-key forward references
within CREATE SCHEMA, but it's not clear that the text requires
anything more than that.)  Moreover, the problem will get worse as
we add more subcommand types.  Let's just drop the whole idea and
execute the commands in the order given, which seems like a much
less astonishment-prone definition anyway.  The foreign-key issue
will be handled in a follow-up patch.

This will result in a release-note-worthy incompatibility,
which is that forward references like
        CREATE SCHEMA myschema
            CREATE VIEW myview AS SELECT * FROM mytable
            CREATE TABLE mytable (...);
used to work and no longer will.  Considering how many closely
related variants never worked, this isn't much of a loss.

Along the way, pass down a ParseState so that we can provide an
error cursor for "wrong schema name" and related errors, and fix
transformCreateSchemaStmtElements so that it doesn't scribble
on the parsetree passed to it.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/1075425.1732993688@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a9c350d9ee66745aadcf7c0c95a567752a762171

Modified Files
--------------
doc/src/sgml/ref/create_schema.sgml         |  17 ++--
src/backend/commands/extension.c            |   7 +-
src/backend/commands/schemacmds.c           |  14 +--
src/backend/parser/parse_utilcmd.c          | 132 +++++++++++-----------------
src/backend/tcop/utility.c                  |   4 +-
src/include/commands/schemacmds.h           |   7 +-
src/include/parser/parse_utilcmd.h          |   3 +-
src/test/regress/expected/create_schema.out |  37 ++++++++
src/test/regress/expected/create_view.out   |   2 +
src/test/regress/expected/event_trigger.out |   2 +-
src/test/regress/expected/namespace.out     |   9 +-
src/test/regress/sql/create_schema.sql      |   5 ++
src/test/regress/sql/namespace.sql          |  11 +--
src/tools/pgindent/typedefs.list            |   1 -
14 files changed, 139 insertions(+), 112 deletions(-)



Message-ID: <E1w9pR6-003HJO-2d@gemulon.postgresql.org>
Permalink:  ../E1w9pR6-003HJO-2d@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w9pR6-003HJO-2d@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Don't try to re-order the subcommands of CREATE SCHEMA.
  In-Reply-To: <E1w9pR6-003HJO-2d@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox