参见英文答案 >
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 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。