Reputation: 1
I need to restart the table sequence after manually importing data and want to dynamically use the maximum value (+1) currently present in the id column.
I identify the value with
SELECT coalesce(MAX("id")+1) FROM "termine";
And I update the sequence with
ALTER SEQUENCE termine_id_seq RESTART WITH 123;
How can I use the MAX id within the ALTER instead of the "123"?
Upvotes: 0
Views: 677
Reputation: 12392
Use the setval helper function.
select pg_catalog.setval('termine_id_seq'::regclass, MAX("id"),true) FROM "termine";
Upvotes: 2