pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
3+ messages / 3 participants
[nested] [flat]
* BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
@ 2021-01-05 01:23 PG Bug reporting form <noreply@postgresql.org>
2021-01-05 15:05 ` Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary Hamid Akhtar <hamid.akhtar@gmail.com>
2021-01-05 15:45 ` Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: PG Bug reporting form @ 2021-01-05 01:23 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: dperham@opex.com
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
2021-01-05 01:23 BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary PG Bug reporting form <noreply@postgresql.org>
@ 2021-01-05 15:05 ` Hamid Akhtar <hamid.akhtar@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Hamid Akhtar @ 2021-01-05 15:05 UTC (permalink / raw)
To: dperham@opex.com; pgsql-bugs@lists.postgresql.org
I'm unable to reproduce this issue on CentOS7. Here's what I get:
------------------------------------------------------------
psql (12.5)
Type "help" for help.
postgres=# create table foo ( bar text );
CREATE TABLE
postgres=# alter table if exists foo add column if not exists id bigserial;
ALTER TABLE
postgres=# alter table if exists foo add column if not exists id bigserial;
NOTICE: column "id" of relation "foo" already exists, skipping
ALTER TABLE
------------------------------------------------------------
Can you please confirm if you are building from source or using any
standard postgresql packages?
On Tue, Jan 5, 2021 at 2:55 PM PG Bug reporting form <noreply@postgresql.org>
wrote:
> 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
>
>
--
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca
ADDR: 10318 WHALLEY BLVD, Surrey, BC
CELL:+923335449950 EMAIL: mailto:hamid.akhtar@highgo.ca
SKYPE: engineeredvirus
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary
2021-01-05 01:23 BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary PG Bug reporting form <noreply@postgresql.org>
@ 2021-01-05 15:45 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2021-01-05 15:45 UTC (permalink / raw)
To: dperham@opex.com; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> ALTER TABLE IF EXIST foo ADD COLUMN IF NOT EXISTS id BIGSERIAL PRIMARY KEY;
> Fails if "id" exists and is already the primary key.
Yeah, known problem. This is fixed in v13, but the fix seemed too
invasive for a back-patch (see [1] and follow-on fixes).
regards, tom lane
[1] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=1281a5c90
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-01-05 15:45 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 01:23 BUG #16805: "ALTER TABLE ... ADD COLUMN IF NOT EXISTS ... PRIMARY KEY" fails if column exists and is the primary PG Bug reporting form <noreply@postgresql.org>
2021-01-05 15:05 ` Hamid Akhtar <hamid.akhtar@gmail.com>
2021-01-05 15:45 ` Tom Lane <tgl@sss.pgh.pa.us>
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