PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID15670
PG Version11.2
OSDebian 9.8
Opened2019-03-05 13:52:16+00
Reported byMichael Binder
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      15670
Logged by:          Michael Binder
Email address:      (redacted)
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

Messages

DateAuthorSubject
2019-03-05 13:52:16+00PG Bug reporting formBUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution
2019-03-05 15:14:40+00Tom LaneRe: BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution
2019-03-05 15:16:10+00Amit LangoteRe: BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution