用于检索当前(在运行查询时)序列值的选项 [英] Options to retrieve the current (on a moment of running query) sequence value

查看:72
本文介绍了用于检索当前(在运行查询时)序列值的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Postgresql 8.4中获取当前序列值?

How is it possible to get the current sequence value in postgresql 8.4?

注意:我需要某种统计信息的值,只需检索和存储即可。

Note: I need the value for the some sort of statistics, just retrieve and store. Nothing related to the concurrency and race conditions in case of manually incrementing it isn't relevant to the question.

注2:序列在多个表之间共享

Note 2: The sequence is shared across several tables

注3:当前值将不起作用,原因是:

Note 3: currval won't work because of:


  • 返回当前会话中该序列的nextval最新获得的值

  • 错误:序列<序列名称> ;在本次会议中尚未定义

  • Return the value most recently obtained by nextval for this sequence in the current session
  • ERROR: currval of sequence "<sequence name>" is not yet defined in this session

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

My current idea: is to parse DDL, which is weird

推荐答案

您可以使用:

SELECT last_value FROM sequence_name;

更新
记录在创建序列语句:


尽管不能直接更新序列,但是可以使用查询
,例如:

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

SELECT * FROM name;

SELECT * FROM name;

检查
序列的参数和当前状态。特别是,序列的 last_value 字段显示
任何会话分配的最后一个值。 (当然,如果其他会话正在积极地
进行nextval调用,则该值在打印时可能已经过时了
。)

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.)

这篇关于用于检索当前(在运行查询时)序列值的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆