BUG #13126: table constraint loses its comment - Mailing list pgsql-bugs

From xi@resolvent.net
Subject BUG #13126: table constraint loses its comment
Date
Msg-id 20150422154850.5198.26685@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13126: table constraint loses its comment  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      13126
Logged by:          Kirill Simonov
Email address:      xi@resolvent.net
PostgreSQL version: 9.4.1
Operating system:   Ubuntu 15.04
Description:

In some circumstances, the comment on a table constraint disappears.  Here
is an example:

-- Create a table with a primary key constraint.

CREATE TYPE enum1 AS ENUM ('foo', 'bar');
CREATE TYPE enum2 AS ENUM ('foo', 'bar', 'baz');

CREATE TABLE t (x enum1 NOT NULL);
ALTER TABLE t ADD CONSTRAINT t_pk PRIMARY KEY (x);
COMMENT ON CONSTRAINT t_pk ON t IS 'the primary key of table "t"';

-- Find the constraint:
--
--    oid
-- ---------
--  3400853
-- (1 row)

SELECT c.oid
FROM pg_constraint c
WHERE c.conname = 't_pk';

-- Find the comment on the constraint:
--
--          description
-- ------------------------------
--  the primary key of table "t"
-- (1 row)

SELECT d.description
FROM
    pg_description d,
    pg_constraint c
WHERE
    d.classoid = 'pg_constraint'::regclass AND
    c.conname = 't_pk' AND
    d.objoid = c.oid;

-- Change the type of the primary key column.

ALTER TABLE t ALTER COLUMN x SET DATA TYPE enum2 USING x::text::enum2;

-- The constraint now has a different OID:
--
-- oid
-- ---------
--  3400855
-- (1 row)

SELECT c.oid
FROM pg_constraint c
WHERE c.conname = 't_pk';

-- The constraint comment is lost:
--
--  description
-- -------------
-- (0 rows)

SELECT d.description
FROM
    pg_description d,
    pg_constraint c
WHERE
    d.classoid = 'pg_constraint'::regclass AND
    c.conname = 't_pk' AND
    d.objoid = c.oid;

-- Cleanup.

DROP TABLE t;
DROP TYPE enum1;
DROP TYPE enum2;

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Installton Error
Next
From: Andres Freund
Date:
Subject: Re: BUG #12910: Memory leak with logical decoding