postgresql – 检索当前(在运行查询的时刻)序列值的选项

前端之家收集整理的这篇文章主要介绍了postgresql – 检索当前(在运行查询的时刻)序列值的选项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在postgresql 8.4中获取当前序列值?

注意:我需要某种统计信息的值,只需检索和存储。在手动递增的情况下,与并发和竞争条件无关的内容与问题无关。

注2:序列在多个表中共享

注3:currval将无法工作,因为:

>返回当前会话中此序列最近获得的值nextval的值
>错误:序列的策略“<序列名称>”在本课程中尚未定义

我目前的想法是:解析DDL,这很奇怪

您可以使用:
SELECT last_value FROM sequence_name;

更新:
这在CREATE SEQUENCE声明中有记录:

Although you cannot update a sequence directly,you can use a query
like:

SELECT * FROM name;

to examine the parameters and current state of a
sequence. In particular,the last_value field of the sequence shows the last value allocated by any session. (Of course,this value might be obsolete by the time it’s printed,if other sessions are actively doing nextval calls.)

原文链接:https://www.f2er.com/postgresql/193176.html

猜你在找的Postgre SQL相关文章