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: dperham@opex.com
Subject: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
Date: Tue, 05 Jan 2021 01:23:04 +0000
Message-ID: <16805-4e3f8b42fbe7622c@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16805
Logged by:          Doug Perham
Email address:      dperham@opex.com
PostgreSQL version: 12.5
Operating system:   Ubuntu 20.04
Description:        

ALTER TABLE IF EXIST foo ADD COLUMN IF NOT EXISTS id BIGSERIAL PRIMARY KEY; 
Fails if "id" exists and is already the primary key.

It seems that everything should be okay if "id" exists and is the primary
key.   Instead, an error is thrown as follows:


test=# create table foo ( bar text );
CREATE TABLE
test=# alter table if exists foo add column if not exists id bigserial
primary key;
ALTER TABLE
test=# alter table if exists foo add column if not exists id bigserial
primary key;
NOTICE:  column "id" of relation "foo" already exists, skipping
ERROR:  multiple primary keys for table "foo" are not allowed



view thread (3+ messages)  latest in thread

Message-ID: <16805-4e3f8b42fbe7622c@postgresql.org>
Permalink:  ../16805-4e3f8b42fbe7622c@postgresql.org/
Also on:    postgresql.org/message-id/16805-4e3f8b42fbe7622c@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, dperham@opex.com
  Subject: Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
  In-Reply-To: <16805-4e3f8b42fbe7622c@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