BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
Date
Msg-id 16805-4e3f8b42fbe7622c@postgresql.org
Whole thread Raw
Responses Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
List pgsql-bugs
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


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #16804: substring() function returns "negative substring length" error when using a large length argument
Next
From: baych igor
Date:
Subject: compiling error on OpenWrt