Postgresql - Using subqueries with alter sequence expressions

前端 未结 2 1367
独厮守ぢ
独厮守ぢ 2020-12-29 01:18

Is it possible to use subqueries within alter expressions in PostgreSQL?

I want to alter a sequence value based on a primary key column value.

I tried using th

2条回答
  •  伪装坚强ぢ
    2020-12-29 01:43

    In addition if you have mixed case object names and you're getting an error like this:

    ERROR: relation "public.mytable_id_seq" does not exist
    

    ... the following version using regclass should be useful:

    select setval('"public"."MyTable_Id_seq"'::regclass, (select MAX("Id") FROM "public"."MyTable"))
    

提交回复
热议问题