Reputation: 6754
Why the next ALTER does not define currval of the sequence comments_comment_id_seq?
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=#
Additional detail
The table which owns the sequence is a child of another table:
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
Upvotes: 2
Views: 380
Reputation: 3467
When you restart the sequence you set it into a state like it was just created. And in this case you don't have a currval before you first selected a nextval.
Upvotes: 3