currval of sequence "follow_id_seq" is not yet defined in this session

时间:2021-03-17 13:36:09

postgresql上使用

  1. select currval('follow_id_seq');

报错:

  1. currval of sequence "follow_id_seq" is not yet defined in this session

查阅参考资料,发现错误原因是要查当前值,必须先取一次next:执行以下语句,执行成功:

  1. dbname=# select nextval('follow_id_seq');
  2. nextval
  3. ---------
  4. 5347
  5. (1 row)
  6. dbname=# select currval('follow_id_seq');
  7. currval
  8. ---------
  9. 5347
  10. (1 row)

http://sunboyyyl.blog.163.com/blog/static/224738120099135521859/