Hi Jim,

I tested v1 on master. I could reproduce both cases from the commit
message: the column comment landing on the wrong table and the error
when the other table has no matching constraint.

Without the patch:

postgres=# CREATE TABLE src (a int NOT NULL);
CREATE TABLE
postgres=# COMMENT ON COLUMN src.a IS 'column comment';
COMMENT
postgres=# COMMENT ON CONSTRAINT src_a_not_null ON src IS 'nn comment';
COMMENT
postgres=# CREATE TABLE foo (a int);
CREATE TABLE
postgres=# SET search_path = public, pg_temp;
SET
postgres=# COMMENT ON COLUMN foo.a IS 'important comment';
COMMENT
postgres=# CREATE TEMP TABLE foo (LIKE src INCLUDING COMMENTS);
ERROR:  constraint "src_a_not_null" for table "foo" does not exist

With the patch, same tables:

postgres=# SET search_path = public, pg_temp;
SET
postgres=# CREATE TEMP TABLE foo (LIKE src INCLUDING COMMENTS);
CREATE TABLE
postgres=# SELECT n.nspname, relname, col_description(c.oid, 1) AS colcomment
FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = 'foo';
  nspname  | relname |    colcomment
-----------+---------+-------------------
 public    | foo     | important comment
 pg_temp_0 | foo     | column comment
(2 rows)

postgres=# SELECT n.nspname, co.conname, obj_description(co.oid,
'pg_constraint') AS concomment
FROM pg_constraint co
JOIN pg_class c ON c.oid = co.conrelid
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = 'foo';
  nspname  |    conname     | concomment
-----------+----------------+------------
 pg_temp_0 | src_a_not_null | nn comment
(1 row)

public.foo keeps its own comment, and both the column comment and the
NOT NULL constraint comment end up on the temp table with no error.

The test covers the column comment case. Would it be worth also
covering the constraint case from the commit message?

Thanks,
Salma


Reply via email to