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