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

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: rafmsou(at)gmail(dot)com
Subject: BUG #17435: "add column if not exists" always adds new FK on the column
Date: 2022-03-11 23:43:40
Message-ID: 17435-9cd1c9fedec5bfe5@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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?

Responses

Browse pgsql-bugs by date

  From Date Subject
Next 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
Previous Message Tom Lane 2022-03-11 19:53:12 Re: BUG #17385: "RESET transaction_isolation" inside serializable transaction causes Assert at the transaction end