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: olav@backupbay.com
Subject: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate
Date: Mon, 30 Apr 2018 14:22:32 +0000
Message-ID: <152509815280.19803.16118194452213577808@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15180
Logged by:          Olav Gjerde
Email address:      olav@backupbay.com
PostgreSQL version: 10.1
Operating system:   x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 6.3.0
Description:        

Alter table add column if not exists with unique constraint will add extra
duplicate of the unique constraint when the column exists.

Example:
ALTER TABLE api_values ADD COLUMN IF NOT EXISTS master_key bigint NULL
UNIQUE;

If you run this several times you will get more unique constraints:
"api_values_master_key_key" UNIQUE CONSTRAINT, btree (master_key)
"api_values_master_key_key1" UNIQUE CONSTRAINT, btree (master_key)
"api_values_master_key_key2" UNIQUE CONSTRAINT, btree (master_key)

Workaround is just dropping the constraint if exits before the alter table
add column statement. But I am afraid a lot of developers will enter this
trap as it is kinda unexpected behavior. I read there is a similar problem
with serial/sequences.



Message-ID: <152509815280.19803.16118194452213577808@wrigleys.postgresql.org>
Permalink:  ../152509815280.19803.16118194452213577808@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152509815280.19803.16118194452213577808@wrigleys.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, olav@backupbay.com
  Subject: Re: BUG #15180: Alter table add column if not exists with unique constraint will add extra duplicate
  In-Reply-To: <152509815280.19803.16118194452213577808@wrigleys.postgresql.org>
  References: <152509815280.19803.16118194452213577808@wrigleys.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