From: xi@resolvent.net
To: pgsql-bugs@postgresql.org
Subject: BUG #13126: table constraint loses its comment
Date: Wed, 22 Apr 2015 15:48:50 +0000
Message-ID: <20150422154850.5198.26685@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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;
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: xi@resolvent.net
Subject: Re: BUG #13126: table constraint loses its comment
In-Reply-To: <20150422154850.5198.26685@wrigleys.postgresql.org>
References: <20150422154850.5198.26685@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox