How to set value to sequence in plpgsql ?
This fails in plpgsql
select setval('public.student_id', select max(student_id) from public.student);
How to set value to sequence in plpgsql ?
This fails in plpgsql
select setval('public.student_id', select max(student_id) from public.student);
you can do this instead, imagining public.student_id
is the name of sequence that already exists:
select setval('public.student_id',max(student_id))
from public.student;
All you have to do is surround the subquery with parentheses. That is syntactically required.