pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: rafmsou@gmail.com
Subject: BUG #17435: "add column if not exists" always adds new FK on the column
Date: Fri, 11 Mar 2022 23:43:40 +0000
Message-ID: <17435-9cd1c9fedec5bfe5@postgresql.org> (raw)

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?



view thread (2+ messages)  latest in thread

Message-ID: <17435-9cd1c9fedec5bfe5@postgresql.org>
Permalink:  ../17435-9cd1c9fedec5bfe5@postgresql.org/
Also on:    postgresql.org/message-id/17435-9cd1c9fedec5bfe5@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, rafmsou@gmail.com
  Subject: Re: BUG #17435: "add column if not exists" always adds new FK on the column
  In-Reply-To: <17435-9cd1c9fedec5bfe5@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox