Quantcast
Channel: Syntax error with if column on exist with primary key - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Syntax error with if column on exist with primary key

$
0
0

I want to add a column which's also a primary key if it doesn't already exist on the table. If I do a simple

ALTER TABLE webinars_identities ADD COLUMN IF NOT EXISTS id uuid

It will work but if I do

ALTER TABLE webinars_identities ADD COLUMN IF NOT EXISTS id uuid PRIMARY KEY DEFAULT uuid_generate_v4();

It says it skips the alter table, but for some reason crashes right after:

NOTICE:  column "id" of relation "webinars_identities" already exists, skippingERROR:  multiple primary keys for table "webinars_identities" are not allowed

My original working query was

ALTER TABLE webinars_identities id uuid PRIMARY KEY DEFAULT uuid_generate_v4();

But this is not repeatable without error.

What am I doing wrong here ?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images