Re: BUG #15981: Alter table add column if not exists with constraint fails on constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: e(dot)oneal89(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15981: Alter table add column if not exists with constraint fails on constraint
Date: 2019-08-27 15:33:21
Message-ID: 13277.1566920001@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> CREATE TABLE test(id uuid PRIMARY KEY);
> ALTER TABLE test ADD IF NOT EXISTS id uuid PRIMARY KEY;
> Output: `NOTICE: column "id" of relation "test" already exists, skipping
> ERROR: multiple primary keys for table "test" are not allowed`

Yeah, this is a well-known issue: the IF NOT EXISTS only conditionalizes
creation of the column, but it's reasonable to expect that it should
conditionalize creation of the index as well. There's work afoot to
improve this [1], but it's not moving very fast; at the earliest you
might see it fixed in v13.

regards, tom lane

[1] https://www.postgresql.org/message-id/flat/10365.1558909428%40sss.pgh.pa.us

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-08-27 17:06:37 Re: PostgreSQL12 crash bug report
Previous Message PG Bug reporting form 2019-08-27 15:07:01 BUG #15981: Alter table add column if not exists with constraint fails on constraint