2 -- Tests for things affected by allow_system_table_mods
4 -- We run the same set of commands once with allow_system_table_mods
5 -- off and then again with on.
7 -- The "on" tests should where possible be wrapped in BEGIN/ROLLBACK
8 -- blocks so as to not leave a mess around.
10 CREATE USER regress_user_ast;
12 SET allow_system_table_mods = off;
14 -- create new table in pg_catalog
15 CREATE TABLE pg_catalog.test (a int);
18 CREATE TABLE t1x (a int, b anyarray);
20 -- index on system catalog
21 ALTER TABLE pg_namespace ADD CONSTRAINT foo UNIQUE USING INDEX pg_namespace_nspname_index;
23 -- write to system catalog table as superuser
24 -- (allowed even without allow_system_table_mods)
25 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 0, 'foo');
27 -- write to system catalog table as normal user
28 GRANT INSERT ON pg_description TO regress_user_ast;
29 SET ROLE regress_user_ast;
30 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 1, 'foo');
33 -- policy on system catalog
34 CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%');
36 -- reserved schema name
40 DROP TABLE pg_description;
42 -- truncate of system table
43 TRUNCATE pg_description;
45 -- rename column of system table
46 ALTER TABLE pg_description RENAME COLUMN description TO comment;
48 -- ATSimplePermissions()
49 ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL;
52 ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1;
54 -- foreign key referencing catalog
55 CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description);
57 -- RangeVarCallbackOwnsRelation()
58 CREATE INDEX pg_description_test_index ON pg_description (description);
60 -- RangeVarCallbackForAlterRelation()
61 ALTER TABLE pg_description RENAME TO pg_comment;
62 ALTER TABLE pg_description SET SCHEMA public;
64 -- reserved tablespace name
65 CREATE TABLESPACE pg_foo LOCATION '/no/such/location';
68 CREATE FUNCTION tf1() RETURNS trigger
75 CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1();
76 ALTER TRIGGER t1 ON pg_description RENAME TO t2;
77 --DROP TRIGGER t2 ON pg_description;
80 CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
81 ALTER RULE r1 ON pg_description RENAME TO r2;
82 -- now make one to test dropping:
83 SET allow_system_table_mods TO on;
84 CREATE RULE r2 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
85 RESET allow_system_table_mods;
86 DROP RULE r2 ON pg_description;
88 SET allow_system_table_mods TO on;
89 DROP RULE r2 ON pg_description;
90 RESET allow_system_table_mods;
93 SET allow_system_table_mods = on;
95 -- create new table in pg_catalog
97 CREATE TABLE pg_catalog.test (a int);
102 CREATE TABLE t1 (a int, b anyarray);
105 -- index on system catalog
107 ALTER TABLE pg_namespace ADD CONSTRAINT foo UNIQUE USING INDEX pg_namespace_nspname_index;
110 -- write to system catalog table as superuser
112 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 2, 'foo');
115 -- write to system catalog table as normal user
117 SET ROLE regress_user_ast;
118 INSERT INTO pg_description (objoid, classoid, objsubid, description) VALUES (0, 0, 3, 'foo');
121 -- policy on system catalog
123 CREATE POLICY foo ON pg_description FOR SELECT USING (description NOT LIKE 'secret%');
126 -- reserved schema name
128 CREATE SCHEMA pg_foo;
132 -- (This will fail anyway because it's pinned.)
134 DROP TABLE pg_description;
137 -- truncate of system table
139 TRUNCATE pg_description;
142 -- rename column of system table
144 ALTER TABLE pg_description RENAME COLUMN description TO comment;
147 -- ATSimplePermissions()
149 ALTER TABLE pg_description ALTER COLUMN description SET NOT NULL;
154 ALTER TABLE pg_description ALTER COLUMN description SET STATISTICS -1;
157 -- foreign key referencing catalog
159 CREATE TABLE foo (a oid, b oid, c int, FOREIGN KEY (a, b, c) REFERENCES pg_description);
162 -- RangeVarCallbackOwnsRelation()
164 CREATE INDEX pg_description_test_index ON pg_description (description);
167 -- RangeVarCallbackForAlterRelation()
169 ALTER TABLE pg_description RENAME TO pg_comment;
172 ALTER TABLE pg_description SET SCHEMA public;
175 -- reserved tablespace name
176 SET client_min_messages = error; -- disable ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS warning
177 CREATE TABLESPACE pg_foo LOCATION '/no/such/location';
178 RESET client_min_messages;
181 CREATE TRIGGER t1 BEFORE INSERT ON pg_description EXECUTE FUNCTION tf1();
182 ALTER TRIGGER t1 ON pg_description RENAME TO t2;
183 DROP TRIGGER t2 ON pg_description;
186 CREATE RULE r1 AS ON INSERT TO pg_description DO INSTEAD NOTHING;
187 ALTER RULE r1 ON pg_description RENAME TO r2;
188 DROP RULE r2 ON pg_description;
192 REVOKE ALL ON pg_description FROM regress_user_ast;
193 DROP USER regress_user_ast;