Postgresql and adding a primary key column

When starting from scratch, adding a primary key column takes one line of SQL. However when adding the primary key column on existing data requires more SQL code.

ALTER TABLE your_table ADD COLUMN key_column BIGSERIAL PRIMARY KEY;

That’s the easy line. When you allready have a table and data and wants the primary key column not to start with 1, but with 10000, then it becomes:

ALTER TABLE your_table ADD COLUMN your column INTEGER;
CREATE SEQUENCE your_table_your_column_seq START WITH 10000 OWNED BY your_table.your_column;
ALTER TABLE your_table ALTER COLUMN your column SET DEFAULT nextval(´your_table_your_column_seq');
UPDATE your_table SET your column = nextval('your_table_your_column_seq');
ALTER TABLE your_table ADD PRIMARY KEY(your_column);