Postgresql 如何将值设置为序列?

Postgresql 如何将值设置为序列?,postgresql,postgresql-13,Postgresql,Postgresql 13,如何在plpgsql中将值设置为序列 这在plpgsql中失败 您可以这样做,想象public.student\u id是已经存在的序列的名称: select setval('public.student_id',max(student_id)) from public.student; 您所要做的就是将子查询用括号括起来。这在语法上是必需的。@LaurenzAlbe,您是对的,可以使用子查询。正如您在回答中指出的,它只需要用括号括起来,因此:选择setval'public.student_i

如何在plpgsql中将值设置为序列

这在plpgsql中失败


您可以这样做,想象public.student\u id是已经存在的序列的名称:

select setval('public.student_id',max(student_id))
from public.student;

您所要做的就是将子查询用括号括起来。这在语法上是必需的。

@LaurenzAlbe,您是对的,可以使用子查询。正如您在回答中指出的,它只需要用括号括起来,因此:选择setval'public.student_id',从public.student中选择maxstudent_id;
select setval('public.student_id',max(student_id))
from public.student;