1

I have table with some PRIMARY KEY. And I need to ad one more field which should be new PRIMARY KEY. I am try to do next:

ALTER TABLE some_table
    ALTER COLUMN user_count DROP PRIMARY KEY,
    ADD COLUMN id serial PRIMARY KEY;

but I am getting next error:

Error: pq: syntax error at or near "PRIMARY"

1 Answer 1

3

First, remove the primary key

ALTER TABLE some_table DROP CONSTRAINT user_count

Then add your new one

ALTER TABLE some_table ADD COLUMN id serial PRIMARY KEY
Sign up to request clarification or add additional context in comments.

5 Comments

Error: pq: constraint "user_count" of relation "some_table" does not exist
Well you need to get the proper primary key name, I can't know it
it is proper name
Either the key or the table name is wrong, as the error message suggests. try user_count_pkey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.