[ACCEPTED]-Postgresql - Using subqueries with alter sequence expressions-alter
Accepted answer
I don't believe you can do it like that 4 but you should be able to use the setval 3 function direction which is what the alter 2 does.
select setval('sequenceX', (select max(table_id)+1 from table), false)
The false will make it return the next 1 sequence number as exactly what is given.
In addition if you have mixed case object 3 names and you're getting an error like this:
ERROR: relation "public.mytable_id_seq" does not exist
... the 2 following version using regclass should 1 be useful:
select setval('"public"."MyTable_Id_seq"'::regclass, (select MAX("Id") FROM "public"."MyTable"))
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.