BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution
Date
Msg-id 15670-b9093d589e3cf8db@postgresql.org
Whole thread Raw
Responses Re: BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #15670: alter table .. add column if not exists ...references ...; adds a FK constraint on each execution  (Amit Langote <amitlangote09@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15670
Logged by:          Michael Binder
Email address:      michael@mibi.io
PostgreSQL version: 11.2
Operating system:   Debian 9.8
Description:

Hi,

I don't know if this is the expected behavior but when I execute this
script:

create table test1 (
  id serial primary key,
  name text
);

create table test2 (
  id serial primary key
);

alter table test2 add column if not exists test1_fk integer not null
references test1(id);
alter table test2 add column if not exists test1_fk integer not null
references test1(id);
alter table test2 add column if not exists test1_fk integer not null
references test1(id);


I end up with 3 FK constrains:

select 
    constraint_name
from information_schema.key_column_usage 
where table_name='test2' 
and position_in_unique_constraint is not null;
--
test2_test1_fk_fkey
test2_test1_fk_fkey1
test2_test1_fk_fkey2


best regards,
Michael Binder


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15669: Error with unnest in PG 11 (ERROR: 0A000)
Next
From: Amit Langote
Date:
Subject: Re: BUG #15668: Server crash in transformPartitionRangeBounds