Reputation: 96300
Say I have a temporary table my_table
, and I would like add a column to it that acts as a primary key.
I have tried with:
ALTER TABLE my_table ADD COLUMN id SERIAL;
UPDATE my_table SET id = nextval(pg_get_serial_sequence('my_table','id'));
ALTER TABLE my_table ADD PRIMARY KEY (id);
but the first line complains with:
ERROR: relation"public.my_table" does not exist
Upvotes: 0
Views: 201
Reputation: 324511
Simply:
ALTER TABLE my_table ADD COLUMN id SERIAL PRIMARY KEY;
will work fine.
The problem isn't your query. It's that the table does not exist. Perhaps it's a temporary table in another session? Temporary tables are only visible within the session that created them.
Upvotes: 2