@@ -4,9 +4,12 @@ SELECT attrelid, attname, attgenerated FROM pg_attribute WHERE attgenerated NOT
4
4
----------+---------+--------------
5
5
(0 rows)
6
6
7
+ CREATE SCHEMA generated_stored_tests;
8
+ GRANT USAGE ON SCHEMA generated_stored_tests TO PUBLIC;
9
+ SET search_path = generated_stored_tests;
7
10
CREATE TABLE gtest0 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (55) STORED);
8
11
CREATE TABLE gtest1 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED);
9
- 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;
12
+ 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;
10
13
table_name | column_name | column_default | is_nullable | is_generated | generation_expression
11
14
------------+-------------+----------------+-------------+--------------+-----------------------
12
15
gtest0 | a | | NO | NEVER |
@@ -15,14 +18,14 @@ SELECT table_name, column_name, column_default, is_nullable, is_generated, gener
15
18
gtest1 | b | | YES | ALWAYS | (a * 2)
16
19
(4 rows)
17
20
18
- SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage ORDER BY 1, 2, 3;
21
+ SELECT table_name, column_name, dependent_column FROM information_schema.column_column_usage WHERE table_schema = 'generated_stored_tests' ORDER BY 1, 2, 3;
19
22
table_name | column_name | dependent_column
20
23
------------+-------------+------------------
21
24
gtest1 | a | b
22
25
(1 row)
23
26
24
27
\d gtest1
25
- Table "public .gtest1"
28
+ Table "generated_stored_tests .gtest1"
26
29
Column | Type | Collation | Nullable | Default
27
30
--------+---------+-----------+----------+------------------------------------
28
31
a | integer | | not null |
@@ -270,7 +273,7 @@ SELECT * FROM gtest1_1;
270
273
(0 rows)
271
274
272
275
\d gtest1_1
273
- Table "public .gtest1_1"
276
+ Table "generated_stored_tests .gtest1_1"
274
277
Column | Type | Collation | Nullable | Default
275
278
--------+---------+-----------+----------+------------------------------------
276
279
a | integer | | not null |
@@ -312,7 +315,7 @@ ERROR: column "b" inherits from generated column but specifies identity
312
315
CREATE TABLE gtestx (x int, b int GENERATED ALWAYS AS (a * 22) STORED) INHERITS (gtest1); -- ok, overrides parent
313
316
NOTICE: merging column "b" with inherited definition
314
317
\d+ gtestx
315
- Table "public .gtestx"
318
+ Table "generated_stored_tests .gtestx"
316
319
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
317
320
--------+---------+-----------+----------+-------------------------------------+---------+--------------+-------------
318
321
a | integer | | not null | | plain | |
@@ -348,7 +351,7 @@ NOTICE: merging multiple inherited definitions of column "b"
348
351
NOTICE: moving and merging column "b" with inherited definition
349
352
DETAIL: User-specified column moved to the position of the inherited column.
350
353
\d gtest1_y
351
- Table "public .gtest1_y"
354
+ Table "generated_stored_tests .gtest1_y"
352
355
Column | Type | Collation | Nullable | Default
353
356
--------+---------+-----------+----------+------------------------------------
354
357
a | integer | | not null |
@@ -523,7 +526,7 @@ HINT: Use DROP ... CASCADE to drop the dependent objects too.
523
526
ALTER TABLE gtest10 DROP COLUMN b CASCADE; -- drops c too
524
527
NOTICE: drop cascades to column c of table gtest10
525
528
\d gtest10
526
- Table "public .gtest10"
529
+ Table "generated_stored_tests .gtest10"
527
530
Column | Type | Collation | Nullable | Default
528
531
--------+---------+-----------+----------+---------
529
532
a | integer | | not null |
@@ -622,7 +625,7 @@ CREATE INDEX gtest22c_b_idx ON gtest22c (b);
622
625
CREATE INDEX gtest22c_expr_idx ON gtest22c ((b * 3));
623
626
CREATE INDEX gtest22c_pred_idx ON gtest22c (a) WHERE b > 0;
624
627
\d gtest22c
625
- Table "public .gtest22c"
628
+ Table "generated_stored_tests .gtest22c"
626
629
Column | Type | Collation | Nullable | Default
627
630
--------+---------+-----------+----------+------------------------------------
628
631
a | integer | | |
@@ -726,7 +729,7 @@ CREATE TABLE gtest23x (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STOR
726
729
ERROR: invalid ON DELETE action for foreign key constraint containing generated column
727
730
CREATE TABLE gtest23b (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) STORED REFERENCES gtest23a (x));
728
731
\d gtest23b
729
- Table "public .gtest23b"
732
+ Table "generated_stored_tests .gtest23b"
730
733
Column | Type | Collation | Nullable | Default
731
734
--------+---------+-----------+----------+------------------------------------
732
735
a | integer | | not null |
@@ -805,7 +808,7 @@ DROP TABLE gtest_child3;
805
808
CREATE TABLE gtest_child3 (f1 date NOT NULL, f2 bigint, f3 bigint GENERATED ALWAYS AS (f2 * 33) STORED);
806
809
ALTER TABLE gtest_parent ATTACH PARTITION gtest_child3 FOR VALUES FROM ('2016-09-01') TO ('2016-10-01');
807
810
\d gtest_child
808
- Table "public .gtest_child"
811
+ Table "generated_stored_tests .gtest_child"
809
812
Column | Type | Collation | Nullable | Default
810
813
--------+--------+-----------+----------+-------------------------------------
811
814
f1 | date | | not null |
@@ -814,7 +817,7 @@ ALTER TABLE gtest_parent ATTACH PARTITION gtest_child3 FOR VALUES FROM ('2016-09
814
817
Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
815
818
816
819
\d gtest_child2
817
- Table "public .gtest_child2"
820
+ Table "generated_stored_tests .gtest_child2"
818
821
Column | Type | Collation | Nullable | Default
819
822
--------+--------+-----------+----------+--------------------------------------
820
823
f1 | date | | not null |
@@ -823,7 +826,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
823
826
Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016')
824
827
825
828
\d gtest_child3
826
- Table "public .gtest_child3"
829
+ Table "generated_stored_tests .gtest_child3"
827
830
Column | Type | Collation | Nullable | Default
828
831
--------+--------+-----------+----------+--------------------------------------
829
832
f1 | date | | not null |
@@ -855,7 +858,7 @@ SELECT tableoid::regclass, * FROM gtest_parent ORDER BY 1, 2, 3;
855
858
ALTER TABLE ONLY gtest_parent ALTER COLUMN f3 SET EXPRESSION AS (f2 * 4);
856
859
ALTER TABLE gtest_child ALTER COLUMN f3 SET EXPRESSION AS (f2 * 10);
857
860
\d gtest_parent
858
- Partitioned table "public .gtest_parent"
861
+ Partitioned table "generated_stored_tests .gtest_parent"
859
862
Column | Type | Collation | Nullable | Default
860
863
--------+--------+-----------+----------+-------------------------------------
861
864
f1 | date | | not null |
@@ -865,7 +868,7 @@ Partition key: RANGE (f1)
865
868
Number of partitions: 3 (Use \d+ to list them.)
866
869
867
870
\d gtest_child
868
- Table "public .gtest_child"
871
+ Table "generated_stored_tests .gtest_child"
869
872
Column | Type | Collation | Nullable | Default
870
873
--------+--------+-----------+----------+--------------------------------------
871
874
f1 | date | | not null |
@@ -874,7 +877,7 @@ Number of partitions: 3 (Use \d+ to list them.)
874
877
Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
875
878
876
879
\d gtest_child2
877
- Table "public .gtest_child2"
880
+ Table "generated_stored_tests .gtest_child2"
878
881
Column | Type | Collation | Nullable | Default
879
882
--------+--------+-----------+----------+--------------------------------------
880
883
f1 | date | | not null |
@@ -883,7 +886,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
883
886
Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016')
884
887
885
888
\d gtest_child3
886
- Table "public .gtest_child3"
889
+ Table "generated_stored_tests .gtest_child3"
887
890
Column | Type | Collation | Nullable | Default
888
891
--------+--------+-----------+----------+--------------------------------------
889
892
f1 | date | | not null |
@@ -902,7 +905,7 @@ SELECT tableoid::regclass, * FROM gtest_parent ORDER BY 1, 2, 3;
902
905
-- alter generation expression of parent and all its children altogether
903
906
ALTER TABLE gtest_parent ALTER COLUMN f3 SET EXPRESSION AS (f2 * 2);
904
907
\d gtest_parent
905
- Partitioned table "public .gtest_parent"
908
+ Partitioned table "generated_stored_tests .gtest_parent"
906
909
Column | Type | Collation | Nullable | Default
907
910
--------+--------+-----------+----------+-------------------------------------
908
911
f1 | date | | not null |
@@ -912,7 +915,7 @@ Partition key: RANGE (f1)
912
915
Number of partitions: 3 (Use \d+ to list them.)
913
916
914
917
\d gtest_child
915
- Table "public .gtest_child"
918
+ Table "generated_stored_tests .gtest_child"
916
919
Column | Type | Collation | Nullable | Default
917
920
--------+--------+-----------+----------+-------------------------------------
918
921
f1 | date | | not null |
@@ -921,7 +924,7 @@ Number of partitions: 3 (Use \d+ to list them.)
921
924
Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
922
925
923
926
\d gtest_child2
924
- Table "public .gtest_child2"
927
+ Table "generated_stored_tests .gtest_child2"
925
928
Column | Type | Collation | Nullable | Default
926
929
--------+--------+-----------+----------+-------------------------------------
927
930
f1 | date | | not null |
@@ -930,7 +933,7 @@ Partition of: gtest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
930
933
Partition of: gtest_parent FOR VALUES FROM ('08-01-2016') TO ('09-01-2016')
931
934
932
935
\d gtest_child3
933
- Table "public .gtest_child3"
936
+ Table "generated_stored_tests .gtest_child3"
934
937
Column | Type | Collation | Nullable | Default
935
938
--------+--------+-----------+----------+-------------------------------------
936
939
f1 | date | | not null |
@@ -987,7 +990,7 @@ SELECT * FROM gtest25 ORDER BY a;
987
990
(2 rows)
988
991
989
992
\d gtest25
990
- Table "public .gtest25"
993
+ Table "generated_stored_tests .gtest25"
991
994
Column | Type | Collation | Nullable | Default
992
995
--------+------------------+-----------+----------+------------------------------------------------------
993
996
a | integer | | not null |
@@ -1011,7 +1014,7 @@ ERROR: cannot alter type of a column used by a generated column
1011
1014
DETAIL: Column "a" is used by generated column "x".
1012
1015
ALTER TABLE gtest27 ALTER COLUMN x TYPE numeric;
1013
1016
\d gtest27
1014
- Table "public .gtest27"
1017
+ Table "generated_stored_tests .gtest27"
1015
1018
Column | Type | Collation | Nullable | Default
1016
1019
--------+---------+-----------+----------+--------------------------------------------
1017
1020
a | integer | | |
@@ -1038,7 +1041,7 @@ ALTER TABLE gtest27
1038
1041
ALTER COLUMN b TYPE bigint,
1039
1042
ADD COLUMN x bigint GENERATED ALWAYS AS ((a + b) * 2) STORED;
1040
1043
\d gtest27
1041
- Table "public .gtest27"
1044
+ Table "generated_stored_tests .gtest27"
1042
1045
Column | Type | Collation | Nullable | Default
1043
1046
--------+--------+-----------+----------+------------------------------------------
1044
1047
a | bigint | | |
@@ -1052,7 +1055,7 @@ ALTER TABLE gtest27
1052
1055
ERROR: cannot alter type of a column used by a generated column
1053
1056
DETAIL: Column "a" is used by generated column "x".
1054
1057
\d gtest27
1055
- Table "public .gtest27"
1058
+ Table "generated_stored_tests .gtest27"
1056
1059
Column | Type | Collation | Nullable | Default
1057
1060
--------+--------+-----------+----------+------------------------------------------
1058
1061
a | bigint | | |
@@ -1080,7 +1083,7 @@ SELECT * FROM gtest29;
1080
1083
(2 rows)
1081
1084
1082
1085
\d gtest29
1083
- Table "public .gtest29"
1086
+ Table "generated_stored_tests .gtest29"
1084
1087
Column | Type | Collation | Nullable | Default
1085
1088
--------+---------+-----------+----------+------------------------------------
1086
1089
a | integer | | |
@@ -1102,7 +1105,7 @@ SELECT * FROM gtest29;
1102
1105
(2 rows)
1103
1106
1104
1107
\d gtest29
1105
- Table "public .gtest29"
1108
+ Table "generated_stored_tests .gtest29"
1106
1109
Column | Type | Collation | Nullable | Default
1107
1110
--------+---------+-----------+----------+------------------------------------
1108
1111
a | integer | | |
@@ -1121,7 +1124,7 @@ SELECT * FROM gtest29;
1121
1124
(4 rows)
1122
1125
1123
1126
\d gtest29
1124
- Table "public .gtest29"
1127
+ Table "generated_stored_tests .gtest29"
1125
1128
Column | Type | Collation | Nullable | Default
1126
1129
--------+---------+-----------+----------+---------
1127
1130
a | integer | | |
@@ -1130,7 +1133,7 @@ SELECT * FROM gtest29;
1130
1133
-- check that dependencies between columns have also been removed
1131
1134
ALTER TABLE gtest29 DROP COLUMN a; -- should not drop b
1132
1135
\d gtest29
1133
- Table "public .gtest29"
1136
+ Table "generated_stored_tests .gtest29"
1134
1137
Column | Type | Collation | Nullable | Default
1135
1138
--------+---------+-----------+----------+---------
1136
1139
b | integer | | |
@@ -1143,15 +1146,15 @@ CREATE TABLE gtest30 (
1143
1146
CREATE TABLE gtest30_1 () INHERITS (gtest30);
1144
1147
ALTER TABLE gtest30 ALTER COLUMN b DROP EXPRESSION;
1145
1148
\d gtest30
1146
- Table "public .gtest30"
1149
+ Table "generated_stored_tests .gtest30"
1147
1150
Column | Type | Collation | Nullable | Default
1148
1151
--------+---------+-----------+----------+---------
1149
1152
a | integer | | |
1150
1153
b | integer | | |
1151
1154
Number of child tables: 1 (Use \d+ to list them.)
1152
1155
1153
1156
\d gtest30_1
1154
- Table "public .gtest30_1"
1157
+ Table "generated_stored_tests .gtest30_1"
1155
1158
Column | Type | Collation | Nullable | Default
1156
1159
--------+---------+-----------+----------+---------
1157
1160
a | integer | | |
@@ -1168,15 +1171,15 @@ CREATE TABLE gtest30_1 () INHERITS (gtest30);
1168
1171
ALTER TABLE ONLY gtest30 ALTER COLUMN b DROP EXPRESSION; -- error
1169
1172
ERROR: ALTER TABLE / DROP EXPRESSION must be applied to child tables too
1170
1173
\d gtest30
1171
- Table "public .gtest30"
1174
+ Table "generated_stored_tests .gtest30"
1172
1175
Column | Type | Collation | Nullable | Default
1173
1176
--------+---------+-----------+----------+------------------------------------
1174
1177
a | integer | | |
1175
1178
b | integer | | | generated always as (a * 2) stored
1176
1179
Number of child tables: 1 (Use \d+ to list them.)
1177
1180
1178
1181
\d gtest30_1
1179
- Table "public .gtest30_1"
1182
+ Table "generated_stored_tests .gtest30_1"
1180
1183
Column | Type | Collation | Nullable | Default
1181
1184
--------+---------+-----------+----------+------------------------------------
1182
1185
a | integer | | |
@@ -1337,14 +1340,14 @@ CREATE TABLE gtest28a (
1337
1340
ALTER TABLE gtest28a DROP COLUMN a;
1338
1341
CREATE TABLE gtest28b (LIKE gtest28a INCLUDING GENERATED);
1339
1342
\d gtest28*
1340
- Table "public .gtest28a"
1343
+ Table "generated_stored_tests .gtest28a"
1341
1344
Column | Type | Collation | Nullable | Default
1342
1345
--------+---------+-----------+----------+------------------------------------
1343
1346
b | integer | | |
1344
1347
c | integer | | |
1345
1348
x | integer | | | generated always as (b * 2) stored
1346
1349
1347
- Table "public .gtest28b"
1350
+ Table "generated_stored_tests .gtest28b"
1348
1351
Column | Type | Collation | Nullable | Default
1349
1352
--------+---------+-----------+----------+------------------------------------
1350
1353
b | integer | | |
0 commit comments