postgresql序列获取max_value

问题描述 投票:2回答:2

如何获得max_value和min_value Postgres序列?

我使用这个语句创建了序列

create sequence seqtest increment 1 minvalue 0 maxvalue 20;

我试过这个查询select max_value from seqtest给出了错误

ERROR:  column "max_value" does not exist
LINE 1: select max_value from seqtest;
HINT:  Perhaps you meant to reference the column "seqtest.last_value".

select * from seqtest的输出

test=# select * from seqtest;

-[ RECORD 1 ]-
last_value | 0
log_cnt    | 0
is_called  | f
sql postgresql sequence
2个回答
3
投票
t=# create sequence seqtest increment 1 minvalue 0 maxvalue 20;
CREATE SEQUENCE
t=# select * from pg_sequence where seqrelid = 'seqtest'::regclass;
 seqrelid | seqtypid | seqstart | seqincrement | seqmax | seqmin | seqcache | seqcycle
----------+----------+----------+--------------+--------+--------+----------+----------
    16479 |       20 |        0 |            1 |     20 |      0 |        1 | f
(1 row)

Postgres 10推出了新目录:https://www.postgresql.org/docs/10/static/catalog-pg-sequence.html

还有:https://www.postgresql.org/docs/current/static/release-10.html

。将序列的元数据字段移动到新的pg_sequence系统目录中(Peter Eisentraut)

序列关系现在只存储可由nextval()修改的字段,即last_value,log_cnt和is_called。其他序列属性(例如起始值和增量)保存在pg_sequence目录的相应行中。


1
投票

或者,可以使用命令\ d使用psql提示符来实现

postgres=# \d seqtest
                    Sequence "public.seqtest"
  Type  | Start | Minimum | Maximum | Increment | Cycles? | Cache 
--------+-------+---------+---------+-----------+---------+-------
 bigint |     0 |       0 |      20 |         1 | no      |     1
© www.soinside.com 2019 - 2024. All rights reserved.