Re: CREATE SCHEMA ... CREATE DOMAIN support
Kirill Reshke <reshkekirill@gmail.com>
From: Kirill Reshke <reshkekirill@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter@eisentraut.org>,
jian he <jian.universality@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-01T05:39:20Z
Lists: pgsql-hackers
Attachments
- v2-0001-Don-t-try-to-re-order-the-subcommands-of-CREATE-S.patch (application/octet-stream) patch v2-0001
On Sun, 1 Dec 2024 at 04:33, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I looked at several iterations of the SQL standard
> and cannot find any support for the idea that CREATE SCHEMA needs to
> be any smarter than that. I'd also argue that doing anything else is
> a POLA violation. It's especially a POLA violation if the code
> rearranges a valid user-written command order into an invalid order,
> which is inevitable if we stick with the current approach.
Agreed.
> So attached is a draft patch that simplifies the rule to "do the
> subcommands in the order written".
+1 on this idea.
Here is my 2c to this draft:
1) Report error position on newly added check for temp relation in
non-temp schema.
> + errmsg("cannot create temporary relation in non-temporary schema"),
> + parser_errposition(pstate, relation->location)));
2)
I added some regression tests that might be worth adding:
a) check for a temporary table created within a non-temporary schema
in create_table.sql, akin to existing check in create_view.sql.
b) Also explicitly check that old-style sql creation does not work.
That is, for example,
CREATE SCHEMA test_ns_schema_3
CREATE VIEW abcd_view AS
SELECT a FROM abcd
CREATE TABLE abcd (
a serial
);
fails.
3) Why do we delete this in `create_schema.sgml`? Is this untrue? It
is about order of definition, not creation, isn't it?
> - The SQL standard specifies that the subcommands in <command>CREATE
> - SCHEMA</command> can appear in any order.
P.S.
This section in SQL-92 is the only information I could find about
order of creation.
```
3) Those objects defined by <schema element>s (base tables, views,
constraints, domains, assertions, character sets, translations,
collations, privileges) and their associated descriptors are
effectively created.
```
Look like we are 100% to do it in order of definition
--
Best regards,
Kirill Reshke
Commits
-
Don't try to re-order the subcommands of CREATE SCHEMA.
- a9c350d9ee66 19 (unreleased) landed
-
Execute foreign key constraints in CREATE SCHEMA at the end.
- 404db8f9edbb 19 (unreleased) landed
-
Support more object types within CREATE SCHEMA.
- d516974840f4 19 (unreleased) landed