BUG #17435: "add column if not exists" always adds new FK on the column - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17435: "add column if not exists" always adds new FK on the column
Date
Msg-id 17435-9cd1c9fedec5bfe5@postgresql.org
Whole thread Raw
Responses Re: BUG #17435: "add column if not exists" always adds new FK on the column
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17435
Logged by:          Rafael Sousa
Email address:      rafmsou@gmail.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?


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #17385: "RESET transaction_isolation" inside serializable transaction causes Assert at the transaction end
Next
From: Japin Li
Date:
Subject: Re: BUG #17409: Unable to alter data type of clustered column which is referenced by foreign key