mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
This reverts commitd516974840, along with parts of commit049b742daa("psql: Tighten heuristics for BEGIN/END within CREATE SCHEMA"). While there's nothing particularly wrong withd51697484in itself, it depends ona9c350d9e("Don't try to re-order the subcommands of CREATE SCHEMA"), and concerns have been raised that the compatibility impact of that outweighs the benefit of allowing more object types within CREATE SCHEMA. It's not possible to revert049b742daverbatim, because the CVE-2026-6464 patches3045a25ba("Teach psql to skip in-line COPY ... FROM STDIN data after a failure") andcf754f741("Save/restore more lexer state when skipping text due to \if") depend on infrastructure it added. Instead, rip out just the bits specifically needed to parse CREATE FUNCTION within CREATE SCHEMA. This results in lexer code that matches v18-and-earlier as modified by CVE-2026-6464. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/20260904180712.cc.noahmisch@microsoft.com Backpatch-through: 19
103 lines
3.9 KiB
SQL
103 lines
3.9 KiB
SQL
--
|
|
-- CREATE_SCHEMA
|
|
--
|
|
|
|
-- Schema creation with elements.
|
|
|
|
CREATE ROLE regress_create_schema_role SUPERUSER;
|
|
|
|
-- Cases where schema creation fails as objects are qualified with a schema
|
|
-- that does not match with what's expected.
|
|
-- This checks all the object types that include schema qualifications.
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE SEQUENCE schema_not_existing.seq;
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE TABLE schema_not_existing.tab (id int);
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE VIEW schema_not_existing.view AS SELECT 1;
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE INDEX ON schema_not_existing.tab (id);
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
|
|
EXECUTE FUNCTION schema_trig.no_func();
|
|
-- Again, with a role specification and no schema names.
|
|
SET ROLE regress_create_schema_role;
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE SEQUENCE schema_not_existing.seq;
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE TABLE schema_not_existing.tab (id int);
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE VIEW schema_not_existing.view AS SELECT 1;
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE INDEX ON schema_not_existing.tab (id);
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
|
|
EXECUTE FUNCTION schema_trig.no_func();
|
|
-- Again, with a schema name and a role specification.
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE SEQUENCE schema_not_existing.seq;
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE TABLE schema_not_existing.tab (id int);
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE VIEW schema_not_existing.view AS SELECT 1;
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE INDEX ON schema_not_existing.tab (id);
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
|
|
EXECUTE FUNCTION schema_trig.no_func();
|
|
RESET ROLE;
|
|
|
|
-- Forward references no longer work in general.
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE VIEW abcd_view AS SELECT a FROM abcd
|
|
CREATE TABLE abcd (a int);
|
|
|
|
-- Cases where the schema creation succeeds.
|
|
-- The schema created matches the role name.
|
|
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
|
|
CREATE TABLE regress_create_schema_role.tab (id int);
|
|
\d regress_create_schema_role.tab
|
|
DROP SCHEMA regress_create_schema_role CASCADE;
|
|
-- Again, with a different role specification and no schema names.
|
|
SET ROLE regress_create_schema_role;
|
|
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
|
|
CREATE TABLE regress_create_schema_role.tab (id int);
|
|
\d regress_create_schema_role.tab
|
|
DROP SCHEMA regress_create_schema_role CASCADE;
|
|
-- Again, with a schema name and a role specification.
|
|
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
|
|
CREATE TABLE regress_schema_1.tab (id int);
|
|
\d regress_schema_1.tab
|
|
DROP SCHEMA regress_schema_1 CASCADE;
|
|
RESET ROLE;
|
|
|
|
-- Test forward-referencing foreign key clauses.
|
|
CREATE SCHEMA regress_schema_fk
|
|
CREATE TABLE regress_schema_fk.t2 (
|
|
b int,
|
|
a int REFERENCES t1 DEFERRABLE INITIALLY DEFERRED NOT ENFORCED
|
|
REFERENCES t3 DEFERRABLE INITIALLY DEFERRED,
|
|
CONSTRAINT fk FOREIGN KEY (a) REFERENCES t1 NOT DEFERRABLE)
|
|
|
|
CREATE TABLE regress_schema_fk.t1 (a int PRIMARY KEY)
|
|
|
|
CREATE TABLE t3 (a int PRIMARY KEY)
|
|
|
|
CREATE TABLE t4 (
|
|
b int,
|
|
a int REFERENCES t5 NOT DEFERRABLE ENFORCED
|
|
REFERENCES t6 DEFERRABLE INITIALLY IMMEDIATE,
|
|
CONSTRAINT fk FOREIGN KEY (a) REFERENCES t6 DEFERRABLE INITIALLY DEFERRED)
|
|
|
|
CREATE TABLE t5 (a int, b int, PRIMARY KEY (a))
|
|
|
|
CREATE TABLE t6 (a int, b int, PRIMARY KEY (a));
|
|
|
|
\d regress_schema_fk.t2
|
|
\d regress_schema_fk.t4
|
|
|
|
DROP SCHEMA regress_schema_fk CASCADE;
|
|
|
|
-- Clean up
|
|
DROP ROLE regress_create_schema_role;
|