From: André Hänsel <andre@webkr.de>
To: pgsql-bugs@postgresql.org
Subject: Two constraints with the same name not always allowed
Date: Sun, 2 Sep 2018 09:31:52 +0200
Message-ID: <0c1001d4428f$0942b430$1bc81c90$@webkr.de> (raw)
Hi list,
calling this a bug might be pedantic, but I noticed this inconsistency:
Case 1:
CREATE TABLE t(c integer);
ALTER TABLE t ADD CONSTRAINT foo UNIQUE(c);
ALTER TABLE t ADD CONSTRAINT foo CHECK(c > 1);
-> ERROR: constraint "foo" for relation "t" already exists
Case 2:
CREATE TABLE t(c integer);
ALTER TABLE t ADD CONSTRAINT foo CHECK(c > 1);
ALTER TABLE t ADD CONSTRAINT foo UNIQUE(c);
-> Creates two constraints, both called "foo".
Case 3:
CREATE TABLE t(c integer);
ALTER TABLE t ADD CONSTRAINT t_c_check UNIQUE(c); -- add the UNIQUE with the
same name that the following CHECK will automatically choose
ALTER TABLE t ADD CHECK(c > 1);
-> Creates the UNIQUE constraint as "t_c_check" and the CHECK as
"t_c_check1"
Case 4:
CREATE TABLE t(c integer);
ALTER TABLE t ADD CONSTRAINT t_c_key CHECK(c > 1);
ALTER TABLE t ADD UNIQUE(c);
-> Creates two constraints, both called "t_c_key".
In cases where two constraints with the same name are created, an "ALTER
TABLE t DROP CONSTRAINT ..." drops the UNIQUE first. Issuing the ALTER TABLE
a second time then drops the CHECK.
Regards,
André
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: andre@webkr.de
Subject: Re: Two constraints with the same name not always allowed
In-Reply-To: <0c1001d4428f$0942b430$1bc81c90$@webkr.de>
* 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