Re: BUG #15180: Alter table add column if not exists with uniqueconstraint will add extra duplicate - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #15180: Alter table add column if not exists with uniqueconstraint will add extra duplicate
Date
Msg-id CAKFQuwaKr8fH3y6ermzKQdE+32UosuuGWmz5w=y2NXYfcWGMRQ@mail.gmail.com
Whole thread Raw
In response to Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate
List pgsql-bugs
On Tue, May 1, 2018 at 11:47 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
A possible objection to this design is that right now, you can do

        alter table foo
          add column if not exists f2 text,
          add column if not exists f2 int;

and it will skip the second ADD subcommand because by that point the
column exists.  With this design, both test subcommands would find that
f2 doesn't exist so we'd try to do both ADD subcommands, and the second
one would fail.  That doesn't particularly bother me, because this
command is silly.

​I'd argue its probably not that silly when you consider copy-paste errors - in which case actually failing instead of silently ignoring the second instance of the same name would be looked upon favorably by the user.  And since pg_dump isn't going to be affected by this the new error seems more positive than negative on-the-whole.

As with the serial thread I'm definitely +1 for making this behave in a less surprising manner - and Tom's proposed flow seems to me to match the expected behavior (I agree with Stephen here, I think I got bogged down in the sequence aspects of the previous thread when having it be this simple is preferable).

David J.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate
Next
From: PG Bug reporting form
Date:
Subject: BUG #15183: pg_upgrade and pg_upgrade.exe both corrupt sequences whenmigrating 9.1 10.3