/ # psql -d db -U db
psql (17.2)
Type "help" for help.
skydive=> ALTER TABLE db ADD COLUMN new_id SERIAL;
ALTER TABLE
skydive=> ALTER TABLE db ADD COLUMN new_id SERIAL;
ALTER TABLE
skydive=> SELECT conname
skydive-> FROM pg_constraint
skydive-> WHERE conrelid = 'db'::regclass AND contype = 'p';
conname
--------------
db_pkey
(1 row)
skydive=> ALTER TABLE db DROP CONSTRAINT logbook_pkey;
ALTER TABLE
skydive=> ALTER TABLE db DROP COLUMN id;
ALTER TABLE
skydive=> ALTER TABLE db RENAME COLUMN new_id TO id;
ALTER TABLE
skydive=> ALTER TABLE db ADD PRIMARY KEY (id);
ALTER TABLE