Re: BUG #17435: "add column if not exists" always adds new FK on the column

From: Japin Li <japinli(at)hotmail(dot)com>
To: rafmsou(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17435: "add column if not exists" always adds new FK on the column
Date: 2022-03-12 13:50:21
Message-ID: MEYP282MB1669CE8ADB4E4C0FA10FF42EB60D9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Sat, 12 Mar 2022 at 07:43, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17435
> Logged by: Rafael Sousa
> Email address: rafmsou(at)gmail(dot)com
> PostgreSQL version: 12.10
> Operating system: macOS, linux
> Description:
>
> The statement below aims to add a new column CCC on table XXX and create a
> FK constraint to YYY at the same time:
>
> "alter table XXX add column if not exists CCC uuid references YYY (id);"
>
> I checked the docs and other forum and that seems to be possible. The
> problem is that we end up with multiple FKs created on column CCC when
> running the statement multiple times. I would hope no FK gets created when
> the column already exists, is that correct?

It seems this bug has been fixed in 1281a5c907 [1]. However, it doesn't backpatch to v12.

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1281a5c907

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2022-03-12 21:49:10 Re: BUG #17255: Server crashes in index_delete_sort_cmp() due to race condition with vacuum
Previous Message Japin Li 2022-03-12 00:31:21 Re: BUG #17409: Unable to alter data type of clustered column which is referenced by foreign key