pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17435: "add column if not exists" always adds new FK on the column
2+ messages / 2 participants
[nested] [flat]

* BUG #17435: "add column if not exists" always adds new FK on the column
@ 2022-03-11 23:43  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2022-03-11 23:43 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: rafmsou@gmail.com

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?



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17435: "add column if not exists" always adds new FK on the column
@ 2022-03-12 13:50  Japin Li <japinli@hotmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Japin Li @ 2022-03-12 13:50 UTC (permalink / raw)
  To: rafmsou@gmail.com; pgsql-bugs@lists.postgresql.org


On Sat, 12 Mar 2022 at 07:43, PG Bug reporting form <noreply@postgresql.org> wrote:
> 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?

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.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-03-12 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 23:43 BUG #17435: "add column if not exists" always adds new FK on the column PG Bug reporting form <noreply@postgresql.org>
2022-03-12 13:50 ` Japin Li <japinli@hotmail.com>

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