如何使用表中的特定max(id)更改PostgreSQL中的Sequence?
发布时间:2020-12-13 15:49:52 所属栏目:百科 来源:网络整理
导读:参见英文答案 How to reset postgres’ primary key sequence when it falls out of sync?????????????????????????????????????26个 ???????????? Alter auto-generated sequence????????????????????????????????????2个 我需要正确地遵循SQL脚本语法.在po
参见英文答案 >
How to reset postgres’ primary key sequence when it falls out of sync?????????????????????????????????????26个
>???????????? Alter auto-generated sequence????????????????????????????????????2个 我需要正确地遵循SQL脚本语法.在postgres中,你不能真正将“alter sequence”与“select max(id)”链接起来.那么以PostgreSQL接受它的方式编写脚本的正确方法是什么? 这是脚本,所以你可以知道我需要什么: alter SEQUENCE notification_settings_seq START with (select max(id) from game_user) 解决方法
这将使用新值重新启动序列:
do $$ declare maxid int; begin select max(id) from game_user into maxid; execute 'alter SEQUENCE seq_name RESTART with '|| maxid; end; $$language plpgsql (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |