Two constraints with the same name not always allowed
André Hänsel <andre@webkr.de>
From: André Hänsel <andre@webkr.de>
To: <pgsql-bugs@postgresql.org>
Date: 2018-09-02T07:31:52Z
Lists: pgsql-bugs
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é
Commits
-
Fully enforce uniqueness of constraint names.
- fb466d7b5dbe 11.0 landed
- 17b7c302b5fc 12.0 landed