SEQUENCES
显示有关序列的信息。
示例
创建简单的序列:
=> CREATE SEQUENCE my_seq MAXVALUE 5000 START 150;
CREATE SEQUENCE
返回有关刚创建的序列的信息:
=> \x
Expanded display is on.
=> SELECT * FROM sequences;
-[ RECORD 1 ]-------+------------------
sequence_schema | public
sequence_name | my_seq
owner_name | dbadmin
identity_table_name |
session_cache_count | 250000
allow_cycle | f
output_ordered | f
increment_by | 1
minimum | 1
maximum | 5000
current_value | 149
sequence_schema_id | 45035996273704966
sequence_id | 45035996273844996
owner_id | 45035996273704962
identity_table_id | 0
标识列是仅适用于数字列类型的序列。要识别表中的列(如有)是标识列,请搜索 COLUMNS
表以查找表中的标识列:
=> CREATE TABLE testid (c1 IDENTITY(1, 1, 1000), c2 INT);
=> \x
Expanded display is on.
=> SELECT * FROM COLUMNS WHERE is_identity='t' AND table_name='testid';
-[ RECORD 1 ]------------+------------------
table_id | 45035996274150730
table_schema | public
table_name | testid
is_system_table | f
column_name | c1
data_type | int
data_type_id | 6
data_type_length | 8
character_maximum_length |
numeric_precision |
numeric_scale |
datetime_precision |
interval_precision |
ordinal_position | 1
is_nullable | f
column_default |
is_identity | t
使用 SEQUENCES
表获得关于 testid 中序列的详细信息:
=> SELECT * FROM sequences WHERE identity_table_name='testid';
-[ RECORD 1 ]-------+--------------------
sequence_schema | public
sequence_name | testid_c1_seq
owner_name | dbadmin
identity_table_name | testid
session_cache_count | 1000
allow_cycle | f
output_ordered | f
increment_by | 1
minimum | 1
maximum | 9223372036854775807
current_value | 0
sequence_schema_id | 45035996273704976
sequence_id | 45035996274150770
owner_id | 45035996273704962
identity_table_id | 45035996274150768
使用 vsql 命令 \ds
以返回序列的列表。以下结果显示了先前示例中创建的两个序列。如果存在更多序列,表会将其列出。
新序列的 CurrentValue 比您在 CREATE SEQUENCE
和 IDENTITY
命令中指定的起始编号少 1,因为您还未使用 NEXTVAL 实例化序列来分配其缓存或提供其首批初始值。
=> \ds
List of Sequences
-[ RECORD 1 ]+--------------------
Schema | public
Sequence | my_seq
CurrentValue | 149
IncrementBy | 1
Minimum | 1
Maximum | 5000
AllowCycle | f
Comment |
-[ RECORD 2 ]+--------------------
Schema | public
Sequence | testid_c1_seq
CurrentValue | 0
IncrementBy | 1
Minimum | 1
Maximum | 9223372036854775807
AllowCycle | f
Comment |