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: michael@mibi.io
Subject: BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution
Date: Tue, 05 Mar 2019 13:52:16 +0000
Message-ID: <15670-b9093d589e3cf8db@postgresql.org> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <15670-b9093d589e3cf8db@postgresql.org>
Permalink:  ../15670-b9093d589e3cf8db@postgresql.org/
Also on:    postgresql.org/message-id/15670-b9093d589e3cf8db@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, michael@mibi.io
  Subject: Re: BUG #15670: alter table .. add column if not exists ... references ...; adds a FK constraint on each execution
  In-Reply-To: <15670-b9093d589e3cf8db@postgresql.org>
  References: <15670-b9093d589e3cf8db@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