How to add an auto-incrementing primary key to an existing table, in PostgreSQL

PHOTO EMBED

Tue Feb 02 2021 17:48:42 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira #sql

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.
content_copyCOPY

https://stackoverflow.com/questions/2944499/how-to-add-an-auto-incrementing-primary-key-to-an-existing-table-in-postgresql