On 2025-Jun-26, Fujii Masao wrote:

>  CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) 
> INHERITS (ctlt1);
>  \d+ ctlt1_inh
> -SELECT description FROM pg_description, pg_constraint c WHERE classoid = 
> 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 
> 'ctlt1_inh'::regclass;
> +SELECT conname, description FROM pg_description, pg_constraint c WHERE 
> classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 
> 'ctlt1_inh'::regclass ORDER BY conname COLLATE "C";
> 
> However, since ctlt1_inh is created with INCLUDING COMMENTS, this test
> doesn't seem to demonstrate the case you mentioned — that comments on
> not-null constraints are copied even without INCLUDING CONSTRAINTS.
> Am I misunderstanding?

Hmm, yeah the case I wanted to modify was for ctlt12_comments which does
INCLUDING COMMENTS without constraints, apologies.  In that case it's
better to modify ctlt2 instead, as shown here.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
>From 7c395756e42d718d3a2a467a33239446d2ca1d02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvhe...@kurilemu.de>
Date: Wed, 25 Jun 2025 17:35:03 +0200
Subject: [PATCH] test fixup v2

---
 src/test/regress/expected/create_table_like.out | 15 ++++++++++++---
 src/test/regress/sql/create_table_like.sql      |  4 +++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/test/regress/expected/create_table_like.out 
b/src/test/regress/expected/create_table_like.out
index 1374a972e6e..29a779c2e90 100644
--- a/src/test/regress/expected/create_table_like.out
+++ b/src/test/regress/expected/create_table_like.out
@@ -332,9 +332,10 @@ COMMENT ON CONSTRAINT ctlt1_a_check ON ctlt1 IS 
't1_a_check';
 COMMENT ON INDEX ctlt1_pkey IS 'index pkey';
 COMMENT ON INDEX ctlt1_b_key IS 'index b_key';
 ALTER TABLE ctlt1 ALTER COLUMN a SET STORAGE MAIN;
-CREATE TABLE ctlt2 (c text);
+CREATE TABLE ctlt2 (c text NOT NULL);
 ALTER TABLE ctlt2 ALTER COLUMN c SET STORAGE EXTERNAL;
 COMMENT ON COLUMN ctlt2.c IS 'C';
+COMMENT ON CONSTRAINT ctlt2_c_not_null ON ctlt2 IS 't2_c_not_null';
 CREATE TABLE ctlt3 (a text CHECK (length(a) < 5), c text CHECK (length(c) < 
7));
 ALTER TABLE ctlt3 ALTER COLUMN c SET STORAGE EXTERNAL;
 ALTER TABLE ctlt3 ALTER COLUMN a SET STORAGE MAIN;
@@ -351,9 +352,10 @@ CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, 
LIKE ctlt2 INCLUDING
 
--------+------+-----------+----------+---------+----------+--------------+-------------
  a      | text |           | not null |         | main     |              | 
  b      | text |           |          |         | extended |              | 
- c      | text |           |          |         | external |              | 
+ c      | text |           | not null |         | external |              | 
 Not-null constraints:
     "ctlt1_a_not_null" NOT NULL "a"
+    "ctlt2_c_not_null" NOT NULL "c"
 
 CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 
INCLUDING COMMENTS);
 \d+ ctlt12_comments
@@ -362,9 +364,16 @@ CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING 
COMMENTS, LIKE ctlt2 INCLUDIN
 
--------+------+-----------+----------+---------+----------+--------------+-------------
  a      | text |           | not null |         | extended |              | A
  b      | text |           |          |         | extended |              | B
- c      | text |           |          |         | extended |              | C
+ c      | text |           | not null |         | extended |              | C
 Not-null constraints:
     "ctlt1_a_not_null" NOT NULL "a"
+    "ctlt2_c_not_null" NOT NULL "c"
+
+SELECT conname, description FROM pg_description, pg_constraint c WHERE 
classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 
'ctlt12_comments'::regclass;
+     conname      |  description  
+------------------+---------------
+ ctlt2_c_not_null | t2_c_not_null
+(1 row)
 
 CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) 
INHERITS (ctlt1);
 NOTICE:  merging column "a" with inherited definition
diff --git a/src/test/regress/sql/create_table_like.sql 
b/src/test/regress/sql/create_table_like.sql
index 6da7f4f0557..bf8702116a7 100644
--- a/src/test/regress/sql/create_table_like.sql
+++ b/src/test/regress/sql/create_table_like.sql
@@ -143,9 +143,10 @@ COMMENT ON INDEX ctlt1_pkey IS 'index pkey';
 COMMENT ON INDEX ctlt1_b_key IS 'index b_key';
 ALTER TABLE ctlt1 ALTER COLUMN a SET STORAGE MAIN;
 
-CREATE TABLE ctlt2 (c text);
+CREATE TABLE ctlt2 (c text NOT NULL);
 ALTER TABLE ctlt2 ALTER COLUMN c SET STORAGE EXTERNAL;
 COMMENT ON COLUMN ctlt2.c IS 'C';
+COMMENT ON CONSTRAINT ctlt2_c_not_null ON ctlt2 IS 't2_c_not_null';
 
 CREATE TABLE ctlt3 (a text CHECK (length(a) < 5), c text CHECK (length(c) < 
7));
 ALTER TABLE ctlt3 ALTER COLUMN c SET STORAGE EXTERNAL;
@@ -162,6 +163,7 @@ CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, 
LIKE ctlt2 INCLUDING
 \d+ ctlt12_storage
 CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 
INCLUDING COMMENTS);
 \d+ ctlt12_comments
+SELECT conname, description FROM pg_description, pg_constraint c WHERE 
classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 
'ctlt12_comments'::regclass;
 CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) 
INHERITS (ctlt1);
 \d+ ctlt1_inh
 SELECT description FROM pg_description, pg_constraint c WHERE classoid = 
'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 
'ctlt1_inh'::regclass;
-- 
2.39.5

Reply via email to