@@ -1017,6 +1017,98 @@ create table cnn2_part1(a int primary key);
1017
1017
alter table cnn2_parted attach partition cnn2_part1 for values in (1);
1018
1018
ERROR: column "a" in child table must be marked NOT NULL
1019
1019
drop table cnn2_parted, cnn2_part1;
1020
+ -- columns in regular and LIKE inheritance should be marked not-nullable
1021
+ -- for primary keys, even if those are deferred
1022
+ CREATE TABLE notnull_tbl4 (a INTEGER PRIMARY KEY INITIALLY DEFERRED);
1023
+ CREATE TABLE notnull_tbl4_lk (LIKE notnull_tbl4);
1024
+ CREATE TABLE notnull_tbl4_lk2 (LIKE notnull_tbl4 INCLUDING INDEXES);
1025
+ CREATE TABLE notnull_tbl4_lk3 (LIKE notnull_tbl4 INCLUDING INDEXES, CONSTRAINT a_nn NOT NULL a);
1026
+ CREATE TABLE notnull_tbl4_cld () INHERITS (notnull_tbl4);
1027
+ CREATE TABLE notnull_tbl4_cld2 (PRIMARY KEY (a) DEFERRABLE) INHERITS (notnull_tbl4);
1028
+ CREATE TABLE notnull_tbl4_cld3 (PRIMARY KEY (a) DEFERRABLE, CONSTRAINT a_nn NOT NULL a) INHERITS (notnull_tbl4);
1029
+ \d+ notnull_tbl4
1030
+ Table "public.notnull_tbl4"
1031
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1032
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1033
+ a | integer | | not null | | plain | |
1034
+ Indexes:
1035
+ "notnull_tbl4_pkey" PRIMARY KEY, btree (a) DEFERRABLE INITIALLY DEFERRED
1036
+ Child tables: notnull_tbl4_cld,
1037
+ notnull_tbl4_cld2,
1038
+ notnull_tbl4_cld3
1039
+
1040
+ \d+ notnull_tbl4_lk
1041
+ Table "public.notnull_tbl4_lk"
1042
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1043
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1044
+ a | integer | | not null | | plain | |
1045
+ Not-null constraints:
1046
+ "notnull_tbl4_lk_a_not_null" NOT NULL "a"
1047
+
1048
+ \d+ notnull_tbl4_lk2
1049
+ Table "public.notnull_tbl4_lk2"
1050
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1051
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1052
+ a | integer | | not null | | plain | |
1053
+ Indexes:
1054
+ "notnull_tbl4_lk2_pkey" PRIMARY KEY, btree (a) DEFERRABLE INITIALLY DEFERRED
1055
+
1056
+ \d+ notnull_tbl4_lk3
1057
+ Table "public.notnull_tbl4_lk3"
1058
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1059
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1060
+ a | integer | | not null | | plain | |
1061
+ Indexes:
1062
+ "notnull_tbl4_lk3_pkey" PRIMARY KEY, btree (a) DEFERRABLE INITIALLY DEFERRED
1063
+ Not-null constraints:
1064
+ "a_nn" NOT NULL "a"
1065
+
1066
+ \d+ notnull_tbl4_cld
1067
+ Table "public.notnull_tbl4_cld"
1068
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1069
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1070
+ a | integer | | not null | | plain | |
1071
+ Not-null constraints:
1072
+ "notnull_tbl4_cld_a_not_null" NOT NULL "a" (inherited)
1073
+ Inherits: notnull_tbl4
1074
+
1075
+ \d+ notnull_tbl4_cld2
1076
+ Table "public.notnull_tbl4_cld2"
1077
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1078
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1079
+ a | integer | | not null | | plain | |
1080
+ Indexes:
1081
+ "notnull_tbl4_cld2_pkey" PRIMARY KEY, btree (a) DEFERRABLE
1082
+ Not-null constraints:
1083
+ "notnull_tbl4_cld2_a_not_null" NOT NULL "a" (inherited)
1084
+ Inherits: notnull_tbl4
1085
+
1086
+ \d+ notnull_tbl4_cld3
1087
+ Table "public.notnull_tbl4_cld3"
1088
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1089
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1090
+ a | integer | | not null | | plain | |
1091
+ Indexes:
1092
+ "notnull_tbl4_cld3_pkey" PRIMARY KEY, btree (a) DEFERRABLE
1093
+ Not-null constraints:
1094
+ "a_nn" NOT NULL "a" (local, inherited)
1095
+ Inherits: notnull_tbl4
1096
+
1097
+ -- leave these tables around for pg_upgrade testing
1098
+ -- also, if a NOT NULL is dropped underneath a deferrable PK, the column
1099
+ -- should still be nullable afterwards. This mimics what pg_dump does.
1100
+ CREATE TABLE notnull_tbl5 (a INTEGER CONSTRAINT a_nn NOT NULL);
1101
+ ALTER TABLE notnull_tbl5 ADD PRIMARY KEY (a) DEFERRABLE;
1102
+ ALTER TABLE notnull_tbl5 DROP CONSTRAINT a_nn;
1103
+ \d+ notnull_tbl5
1104
+ Table "public.notnull_tbl5"
1105
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1106
+ --------+---------+-----------+----------+---------+---------+--------------+-------------
1107
+ a | integer | | not null | | plain | |
1108
+ Indexes:
1109
+ "notnull_tbl5_pkey" PRIMARY KEY, btree (a) DEFERRABLE
1110
+
1111
+ DROP TABLE notnull_tbl5;
1020
1112
-- Comments
1021
1113
-- Setup a low-level role to enforce non-superuser checks.
1022
1114
CREATE ROLE regress_constraint_comments;
0 commit comments