You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make CREATE TABLE LIKE copy comments on NOT NULL constraints when requested.
Commit 14e87ff introduced support for adding comments to NOT NULL
constraints. However, CREATE TABLE LIKE INCLUDING COMMENTS did not copy
these comments to the new table. This was an oversight in that commit.
This commit corrects the behavior by ensuring CREATE TABLE LIKE to also copy
the comments on NOT NULL constraints when INCLUDING COMMENTS is specified.
Author: Jian He <[email protected]>
Co-authored-by: Álvaro Herrera <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/[email protected]
SELECT conname, description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt12_comments'::regclass;
373
+
conname | description
374
+
------------------+---------------
375
+
ctlt2_c_not_null | t2_c_not_null
376
+
(1 row)
368
377
369
378
CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
370
379
NOTICE: merging column "a" with inherited definition
@@ -529,7 +538,9 @@ NOTICE: drop cascades to table inhe
529
538
-- LIKE must respect NO INHERIT property of constraints
530
539
CREATE TABLE noinh_con_copy (a int CHECK (a > 0) NO INHERIT, b int not null,
531
540
c int not null no inherit);
532
-
CREATE TABLE noinh_con_copy1 (LIKE noinh_con_copy INCLUDING CONSTRAINTS);
541
+
COMMENT ON CONSTRAINT noinh_con_copy_b_not_null ON noinh_con_copy IS 'not null b';
542
+
COMMENT ON CONSTRAINT noinh_con_copy_c_not_null ON noinh_con_copy IS 'not null c no inherit';
543
+
CREATE TABLE noinh_con_copy1 (LIKE noinh_con_copy INCLUDING CONSTRAINTS INCLUDING COMMENTS);
Copy file name to clipboardExpand all lines: src/test/regress/sql/create_table_like.sql
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -143,9 +143,10 @@ COMMENT ON INDEX ctlt1_pkey IS 'index pkey';
143
143
COMMENT ON INDEX ctlt1_b_key IS 'index b_key';
144
144
ALTERTABLE ctlt1 ALTER COLUMN a SET STORAGE MAIN;
145
145
146
-
CREATETABLEctlt2 (c text);
146
+
CREATETABLEctlt2 (c textNOT NULL);
147
147
ALTERTABLE ctlt2 ALTER COLUMN c SET STORAGE EXTERNAL;
148
148
COMMENT ON COLUMN ctlt2.c IS 'C';
149
+
COMMENT ON CONSTRAINT ctlt2_c_not_null ON ctlt2 IS 't2_c_not_null';
149
150
150
151
CREATETABLEctlt3 (a textCHECK (length(a) <5), c textCHECK (length(c) <7));
151
152
ALTERTABLE ctlt3 ALTER COLUMN c SET STORAGE EXTERNAL;
@@ -162,6 +163,7 @@ CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, LIKE ctlt2 INCLUDING
162
163
\d+ ctlt12_storage
163
164
CREATETABLEctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 INCLUDING COMMENTS);
164
165
\d+ ctlt12_comments
166
+
SELECT conname, description FROM pg_description, pg_constraint c WHERE classoid ='pg_constraint'::regclass AND objoid =c.oidANDc.conrelid='ctlt12_comments'::regclass;
165
167
CREATETABLEctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
166
168
\d+ ctlt1_inh
167
169
SELECT description FROM pg_description, pg_constraint c WHERE classoid ='pg_constraint'::regclass AND objoid =c.oidANDc.conrelid='ctlt1_inh'::regclass;
0 commit comments