ALTER TABLE test1 ADD COLUMN id SERIAL PRIMARY KEY; This is all you need to: Add the id column Populate it with a sequence from 1 to count(*). Set it as primary key / not null.
ALTER TABLE test1 ADD COLUMN id SERIAL PRIMARY KEY; This is all you need to: Add the id column Populate it with a sequence from 1 to count(*). Set it as primary key / not null.