YMatrix
Quick Start
Simulate Time Series Scenarios
Standard Cluster Deployment
Data Modeling
Connecting to The database
Data Writing
Data Migration
Data Query
Scene Application Examples
Federal Query
Maintenance and Monitoring
Global Maintenance
Partition Maintenance
Backup and Restore
Cluster Expansion
Enable Mirroring
Resource Management
Security
Monitoring
Performance Tuning
Troubleshooting
Reference Guide
Tool Guide
Data Type
Storage Engine
Execution Engine
Stream Processing
DR (Disaster Recovery)
Configuration Parameters
Index
Extension
SQL Reference
FAQ
Define a new sequence generator.
CREATE [TEMPORARY | TEMP] SEQUENCE name
[INCREMENT [BY] value]
[MINVALUE minvalue | NO MINVALUE]
[MAXVALUE maxvalue | NO MAXVALUE]
[START [ WITH ] start]
[CACHE cache]
[[NO] CYCLE]
[OWNED BY { table.column | NONE }]
CREATE SEQUENCE Creates a new sequence generator. This involves creating and initializing new special single row tables. The generator will be owned by the user who issued the command.
If a schema name is specified, a sequence is created in the specified schema. Otherwise, it will be created in the current mode. Temporary sequences exist in special schemas, so the schema name may not be given when creating a temporary sequence. The sequence name must be different from the name of any other sequence, table, index, view, or external table in the same schema.
After creating a sequence, you can use the nextval() function to operate on the sequence. For example, to insert a row into a table that gets the next value of the sequence:
INSERT INTO distributors VALUES (nextval('myserial'), 'acme');
You can also use the function setval() to operate on sequences, but only for queries that do not operate on distributed data. For example, allow the following query because it resets the sequence counter value of the sequence generator process on the Master:
SELECT setval('myserial', 201);
But the following query will be rejected in the YMatrix database because it operates on distributed data:
INSERT INTO product VALUES (setval('myserial', 201), 'gizmo');
In a regular (non-distributed) database, functions that operate on sequences go to the local sequence list to get the value as needed. However, remember that in the YMatrix database, each Segment is its own different database process. Therefore, a Segment requires a real single point to get the sequence value so that all Segments are incremented correctly and the sequences are advanced in the correct order. The sequence server process runs on the Master and is the real point of the sequence in the YMatrix distributed database. Segment gets sequence values from Master at runtime.
Due to this distributed sequence design, there are some limitations on the functions of sequence operations in the YMatrix database:
Although you cannot update the sequence directly, you can use a query like the following:
SELECT * FROM sequence_name;
Check the sequence's parameters and current status. In particular, the last_value field of the sequence displays the last value assigned by any session.
TEMPORARY | TEMP
name
Increment
minvalue
NO MINVALUE
maxvalue
NO MAXVALUE
start
cache
CYCLE
NO CYCLE
OWNED BY table.column
OWNED BY NONE
The sequence is based on bigint arithmetic, so the range cannot exceed the range of octet integers (-9223372036854775808 to 9223372036854775807).
Although multiple sessions are guaranteed to assign different sequence values, these values may be generated in order when all sessions are considered. For example, session A might retain the value 1..10 and return nextval = 1, and then session B might retain the value 11..20 and return nextval = 11 before session A generates nextval = 2. So you should just assume that nextval() values are all different, rather than generating them purely in order. Likewise, last_value will reflect the latest value retained by any session, whether nextval() has returned it or not.
Create a sequence called myseq:
CREATE SEQUENCE myseq START 101;
Insert a row in the table to get the next value of the sequence named idseq:
INSERT INTO distributors VALUES (nextval('idseq'), 'acme');
Reset the sequence counter value on the Master:
SELECT setval('myseq', 201);
Illegal use of setval() in a YMatrix database (set sequence values on distributed data):
INSERT INTO product VALUES (setval('myseq', 201), 'gizmo');
CREATE SEQUENCE complies with SQL standards, except for the following: