From 9acecbb3f45fa45522e8a4d2f10c29819d3abf54 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 29 Apr 2024 09:46:43 +0200 Subject: [PATCH v0 2/5] Put generated_stored test objects in a schema This avoids naming conflicts with concurrent tests with similarly named objects. Currently, there are none, but a tests for virtual generated columns are planned to be added. --- .../regress/expected/generated_stored.out | 71 ++++++++++--------- src/test/regress/sql/generated_stored.sql | 8 ++- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/test/regress/expected/generated_stored.out b/src/test/regress/expected/generated_stored.out index a4f37736623..6682092124c 100644 --- a/src/test/regress/expected/generated_stored.out +++ b/src/test/regress/expected/generated_stored.out @@ -4,9 +4,12 @@ SELECT attrelid, attname, attgenerated FROM pg_attribute WHERE attgenerated NOT ----------+---------+-------------- (0 rows) +CREATE SCHEMA generated_stored_tests; +GRANT USAGE ON SCHEMA generated_stored_tests TO PUBLIC; +SET search_path = generated_stored_tests; CREATE TABLE gtest0 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (55) STORED); CREATE TABLE gtest1 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED); -SELECT table_name, column_name, column_default, is_nullable, is_generated, generation_expression FROM information_schema.columns WHERE table_name LIKE 'gtest_' ORDER BY 1, 2; +SELECT table_name, column_name, column_default, is_nullable, is_generated, generation_expression FROM information_schema.columns WHERE table_schema = 'generated_stored_tests' ORDER BY 1, 2; table_name | column_name | column_default | is_nullable | is_generated | generation_expression ------------+-------------+----------------+-------------+--------------+----------------------- gtest0 | a | | NO | NEVER | @@ -15,14 +18,14 @@ SELECT table_name, column_name, column_default, is_nullable, is_generated, gener gtest1 | b | | YES | ALWAYS | (a * 2) (4 rows) -SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage ORDER BY 1, 2, 3; +SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage WHERE table_schema = 'generated_stored_tests' ORDER BY 1, 2, 3; table_name | column_name | dependent_column ------------+-------------+------------------ gtest1 | a | b (1 row) \d gtest1 - Table "public.gtest1" + Table "generated_stored_tests.gtest1" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | not null | @@ -270,7 +273,7 @@ SELECT * FROM gtest1_1; (0 rows) \d gtest1_1 - Table "public.gtest1_1" + Table "generated_stored_tests.gtest1_1" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | not null | @@ -312,7 +315,7 @@ ERROR: column "b" inherits from generated column but specifies identity CREATE TABLE gtestx (x int, b int GENERATED ALWAYS AS (a * 22) STORED) INHERITS (gtest1); -- ok, overrides parent NOTICE: merging column "b" with inherited definition \d+ gtestx - Table "public.gtestx" + Table "generated_stored_tests.gtestx" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+-------------------------------------+---------+--------------+------------- a | integer | | not null | | plain | | @@ -350,7 +353,7 @@ NOTICE: merging multiple inherited definitions of column "b" NOTICE: moving and merging column "b" with inherited definition DETAIL: User-specified column moved to the position of the inherited column. \d gtest1_y - Table "public.gtest1_y" + Table "generated_stored_tests.gtest1_y" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | not null | @@ -525,7 +528,7 @@ HINT: Use DROP ... CASCADE to drop the dependent objects too. ALTER TABLE gtest10 DROP COLUMN b CASCADE; -- drops c too NOTICE: drop cascades to column c of table gtest10 \d gtest10 - Table "public.gtest10" + Table "generated_stored_tests.gtest10" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | not null | @@ -624,7 +627,7 @@ CREATE INDEX gtest22c_b_idx ON gtest22c (b); CREATE INDEX gtest22c_expr_idx ON gtest22c ((b * 3)); CREATE INDEX gtest22c_pred_idx ON gtest22c (a) WHERE b > 0; \d gtest22c - Table "public.gtest22c" + Table "generated_stored_tests.gtest22c" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | | @@ -728,7 +731,7 @@ CREATE TABLE gtest23x (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STOR ERROR: invalid ON DELETE action for foreign key constraint containing generated column CREATE TABLE gtest23b (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED REFERENCES gtest23a (x)); \d gtest23b - Table "public.gtest23b" + Table "generated_stored_tests.gtest23b" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | not null | @@ -807,7 +810,7 @@ DROP TABLE gtest_child3; CREATE TABLE gtest_child3 (f1 date NOT NULL, f2 bigint, f3 bigint GENERATED ALWAYS AS (f2 * 33) STORED); ALTER TABLE gtest_parent ATTACH PARTITION gtest_child3 FOR VALUES FROM ('2016-09-01') TO ('2016-10-01'); \d gtest_child - Table "public.gtest_child" + Table "generated_stored_tests.gtest_child" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -816,7 +819,7 @@ ALTER TABLE gtest_parent ATTACH PARTITION gtest_child3 FOR VALUES FROM ('2016-09 Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') \d gtest_child2 - Table "public.gtest_child2" + Table "generated_stored_tests.gtest_child2" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+-------------------------------------- f1 | date | | not null | @@ -825,7 +828,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016') \d gtest_child3 - Table "public.gtest_child3" + Table "generated_stored_tests.gtest_child3" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+-------------------------------------- f1 | date | | not null | @@ -857,7 +860,7 @@ SELECT tableoid::regclass, * FROM gtest_parent ORDER BY 1, 2, 3; ALTER TABLE ONLY gtest_parent ALTER COLUMN f3 SET EXPRESSION AS (f2 * 4); ALTER TABLE gtest_child ALTER COLUMN f3 SET EXPRESSION AS (f2 * 10); \d gtest_parent - Partitioned table "public.gtest_parent" + Partitioned table "generated_stored_tests.gtest_parent" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -867,7 +870,7 @@ Partition key: RANGE (f1) Number of partitions: 3 (Use \d+ to list them.) \d gtest_child - Table "public.gtest_child" + Table "generated_stored_tests.gtest_child" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+-------------------------------------- f1 | date | | not null | @@ -876,7 +879,7 @@ Number of partitions: 3 (Use \d+ to list them.) Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') \d gtest_child2 - Table "public.gtest_child2" + Table "generated_stored_tests.gtest_child2" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+-------------------------------------- f1 | date | | not null | @@ -885,7 +888,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016') \d gtest_child3 - Table "public.gtest_child3" + Table "generated_stored_tests.gtest_child3" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+-------------------------------------- f1 | date | | not null | @@ -904,7 +907,7 @@ SELECT tableoid::regclass, * FROM gtest_parent ORDER BY 1, 2, 3; -- alter generation expression of parent and all its children altogether ALTER TABLE gtest_parent ALTER COLUMN f3 SET EXPRESSION AS (f2 * 2); \d gtest_parent - Partitioned table "public.gtest_parent" + Partitioned table "generated_stored_tests.gtest_parent" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -914,7 +917,7 @@ Partition key: RANGE (f1) Number of partitions: 3 (Use \d+ to list them.) \d gtest_child - Table "public.gtest_child" + Table "generated_stored_tests.gtest_child" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -923,7 +926,7 @@ Number of partitions: 3 (Use \d+ to list them.) Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') \d gtest_child2 - Table "public.gtest_child2" + Table "generated_stored_tests.gtest_child2" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -932,7 +935,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016') Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016') \d gtest_child3 - Table "public.gtest_child3" + Table "generated_stored_tests.gtest_child3" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------- f1 | date | | not null | @@ -989,7 +992,7 @@ SELECT * FROM gtest25 ORDER BY a; (2 rows) \d gtest25 - Table "public.gtest25" + Table "generated_stored_tests.gtest25" Column | Type | Collation | Nullable | Default --------+------------------+-----------+----------+------------------------------------------------------ a | integer | | not null | @@ -1013,7 +1016,7 @@ ERROR: cannot alter type of a column used by a generated column DETAIL: Column "a" is used by generated column "x". ALTER TABLE gtest27 ALTER COLUMN x TYPE numeric; \d gtest27 - Table "public.gtest27" + Table "generated_stored_tests.gtest27" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+-------------------------------------------- a | integer | | | @@ -1039,7 +1042,7 @@ ALTER TABLE gtest27 ALTER COLUMN b TYPE bigint, ADD COLUMN x bigint GENERATED ALWAYS AS ((a + b) * 2) STORED; \d gtest27 - Table "public.gtest27" + Table "generated_stored_tests.gtest27" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------------ a | bigint | | | @@ -1053,7 +1056,7 @@ ALTER TABLE gtest27 ERROR: cannot alter type of a column used by a generated column DETAIL: Column "a" is used by generated column "x". \d gtest27 - Table "public.gtest27" + Table "generated_stored_tests.gtest27" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+------------------------------------------ a | bigint | | | @@ -1081,7 +1084,7 @@ SELECT * FROM gtest29; (2 rows) \d gtest29 - Table "public.gtest29" + Table "generated_stored_tests.gtest29" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | | @@ -1103,7 +1106,7 @@ SELECT * FROM gtest29; (2 rows) \d gtest29 - Table "public.gtest29" + Table "generated_stored_tests.gtest29" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | | @@ -1122,7 +1125,7 @@ SELECT * FROM gtest29; (4 rows) \d gtest29 - Table "public.gtest29" + Table "generated_stored_tests.gtest29" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | | @@ -1131,7 +1134,7 @@ SELECT * FROM gtest29; -- check that dependencies between columns have also been removed ALTER TABLE gtest29 DROP COLUMN a; -- should not drop b \d gtest29 - Table "public.gtest29" + Table "generated_stored_tests.gtest29" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- b | integer | | | @@ -1144,7 +1147,7 @@ CREATE TABLE gtest30 ( CREATE TABLE gtest30_1 () INHERITS (gtest30); ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION; \d gtest30 - Table "public.gtest30" + Table "generated_stored_tests.gtest30" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | | @@ -1152,7 +1155,7 @@ ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION; Number of child tables: 1 (Use \d+ to list them.) \d gtest30_1 - Table "public.gtest30_1" + Table "generated_stored_tests.gtest30_1" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- a | integer | | | @@ -1169,7 +1172,7 @@ CREATE TABLE gtest30_1 () INHERITS (gtest30); ALTER TABLE ONLY gtest30 ALTER COLUMN b DROP EXPRESSION; -- error ERROR: ALTER TABLE / DROP EXPRESSION must be applied to child tables too \d gtest30 - Table "public.gtest30" + Table "generated_stored_tests.gtest30" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | | @@ -1177,7 +1180,7 @@ ERROR: ALTER TABLE / DROP EXPRESSION must be applied to child tables too Number of child tables: 1 (Use \d+ to list them.) \d gtest30_1 - Table "public.gtest30_1" + Table "generated_stored_tests.gtest30_1" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ a | integer | | | @@ -1338,14 +1341,14 @@ CREATE TABLE gtest28a ( ALTER TABLE gtest28a DROP COLUMN a; CREATE TABLE gtest28b (LIKE gtest28a INCLUDING GENERATED); \d gtest28* - Table "public.gtest28a" + Table "generated_stored_tests.gtest28a" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ b | integer | | | c | integer | | | x | integer | | | generated always as (b * 2) stored - Table "public.gtest28b" + Table "generated_stored_tests.gtest28b" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+------------------------------------ b | integer | | | diff --git a/src/test/regress/sql/generated_stored.sql b/src/test/regress/sql/generated_stored.sql index cb55d77821f..c18e0e1f655 100644 --- a/src/test/regress/sql/generated_stored.sql +++ b/src/test/regress/sql/generated_stored.sql @@ -2,12 +2,16 @@ SELECT attrelid, attname, attgenerated FROM pg_attribute WHERE attgenerated NOT IN ('', 's'); +CREATE SCHEMA generated_stored_tests; +GRANT USAGE ON SCHEMA generated_stored_tests TO PUBLIC; +SET search_path = generated_stored_tests; + CREATE TABLE gtest0 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (55) STORED); CREATE TABLE gtest1 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED); -SELECT table_name, column_name, column_default, is_nullable, is_generated, generation_expression FROM information_schema.columns WHERE table_name LIKE 'gtest_' ORDER BY 1, 2; +SELECT table_name, column_name, column_default, is_nullable, is_generated, generation_expression FROM information_schema.columns WHERE table_schema = 'generated_stored_tests' ORDER BY 1, 2; -SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage ORDER BY 1, 2, 3; +SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage WHERE table_schema = 'generated_stored_tests' ORDER BY 1, 2, 3; \d gtest1 -- 2.44.0