pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Olivier Leprêtre <o.lepretre@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: TR: redundant constraint_schema
Date: Sat, 1 Sep 2018 17:50:31 +0200
Message-ID: <5b8ab54c.1c69fb81.1566e.43f0@mx.google.com> (raw)

Hi,

 

Please find a question that didn't get an answer in the pgsql-sql &
pgsql-hackers lists. I hope I'll get an answer here.

 

Thanks,

 

Olivier

 

 

De : Olivier Leprêtre [ <mailto:o.lepretre@gmail.com>
mailto:o.lepretre@gmail.com] 
Envoyé : mercredi 29 août 2018 15:49
À : 'pgsql-sql@lists.postgresql.org'
Objet : redundant constraint_schema

 

Hi,

 

Can someone explain why, when a column is not created (add column if not
exists), a redundant constraint is still created from the REFERENCES part ?

 

 

I have a patching script that is supposed to add column if not existing :

 

ALTER TABLE myschem.table1

          ADD COLUMN IF NOT EXISTS col1 VARCHAR(254) REFERENCES
myschem.table2(col2)

 

When col1 already exists, I expected that nothing would happen. But, when
applying the previous query and then querying :

 

select constraint_name from information_schema.key_column_usage where
constraint_schema='myschem'

 

I notice that a new constraint "table1_col2_fkeyxxx" is created each time
the previous ALTER TABLE ADD COLUMN is called (with xxx being a new number
each time)

 

It seems strange to have second part of statement executed (references) when
first part (add column) was not. Would it be possible that this sort of
query executes "references" first ?

 

Thanks,

 

Olivier

 

view thread (9+ messages)  latest in thread

Message-ID: <5b8ab54c.1c69fb81.1566e.43f0@mx.google.com>
Permalink:  ../5b8ab54c.1c69fb81.1566e.43f0@mx.google.com/
Also on:    postgresql.org/message-id/5b8ab54c.1c69fb81.1566e.43f0@mx.google.com

 · 

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-general@postgresql.org
  Cc: o.lepretre@gmail.com
  Subject: Re: TR: redundant constraint_schema
  In-Reply-To: <5b8ab54c.1c69fb81.1566e.43f0@mx.google.com>
  References: <5b8ab54c.1c69fb81.1566e.43f0@mx.google.com>

* 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