postgresql serial 不自动增长的问题

在手工导入原始数据后,其中的id项为serial类,由原始数据赋值,会遇到不自动增长的问题。

解决方案参考:http://bbs2.chinaunix.net/thread-1353824-1-1.html

serial key其实是由sequence实现的,当你手动给serial列赋值的时候,sequence是不会自增量变化的,当你插入customer 6的时候看看customer_id sequence是多少?

最好不要给serial手工赋值

SELECT setval(‘序列名称’, max(id)) FROM 表;

select setval(‘offlineapp_id_seq’,max(id)) from offlineapp;

This entry was posted in Computer and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string r7rUID to the field below:

以新浪微博帐号登录