Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, olav(at)backupbay(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate
Date: 2018-05-01 20:29:33
Message-ID: 13929.1525206573@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tue, May 1, 2018 at 11:47 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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.

Yeah, good point.

I also noticed while looking at the code that AT_AddOids is a rather
klugy implementation of, effectively, ADD COLUMN IF NOT EXISTS.
Perhaps it'd save code to fold it into this mechanism. Or maybe not,
since the OID column is pretty special-casey anyway.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2018-05-02 14:42:27 Re: power() function in Windows: "value out of range: underflow"
Previous Message PG Bug reporting form 2018-05-01 19:47:43 BUG #15183: pg_upgrade and pg_upgrade.exe both corrupt sequences when migrating 9.1 10.3