Reputation: 465
I want to restart sequence with max+1 of certain table.
SELECT max(id)+1
INTO testVal
FROM project;
ALTER SEQUENCE project_id_seq RESTART testVal;
This gives syntax error at testVal. Can someone please explain me what is a problem, propose alternative solution?
Upvotes: 0
Views: 85
Reputation: 630
for sequences you should be using setval
SELECT SETVAL('project_id_seq', (SELECT max(id)+1 FROM project))
https://www.postgresql.org/docs/current/functions-sequence.html
Upvotes: 2