序列ALTER RESTART不会影响序列的当前值

时间:2014-04-09 07:46:38

标签: sql postgresql

为什么下一个ALTER没有定义序列comments_comment_id_seq的currval?

db=# alter sequence comments_comment_id_seq restart with 65545;
ALTER SEQUENCE
db=# SELECT currval('comments_comment_id_seq');
ERROR:  currval of sequence "comments_comment_id_seq" is not yet defined in this session
db=#

其他详细信息

拥有序列的表是另一个表的子表:

   Column   |            Type             |                             Modifiers              
------------+-----------------------------+--------------------------------------------------------------------
 comment_id | bigint                      | not null default nextval('comments_base_comment_id_seq'::regclass)
 auser_id   | bigint                      | not null
 dt         | timestamp without time zone | not null
 text       | text                        | not null
 is_deleted | smallint                    | default 0
 parent     | bigint                      | default 0
 post_id    | bigint                      | not null
Indexes:
    "comments_pkey" PRIMARY KEY, btree (comment_id)
Inherits: comments_base

1 个答案:

答案 0 :(得分:3)

重新启动序列时,将其设置为刚刚创建的状态。在这种情况下,在您第一次选择下一个字段之前,您没有一个currval。