Sequences
A sequence is a database object inside a schema that hands out consecutive integers. Its usual job is to supply values for an auto-incrementing primary key column, so that rows inserted through the SQL API, the Feature API or an import get unique ids without the client choosing them. Tables created with a serial column get a sequence automatically; the Sequence API is for when you need to create one explicitly, share it between tables, change its start value or increment, or remove it.
Add sequence
A new sequence can be created by providing at least a name.
- Web App
- HTTP
- CLI
Create new sequence
POST https://api.centia.io/api/v4/schemas/rockhall/sequences HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"name": "my_sequence",
"data_type": "bigint",
"increment_by": 1,
"min_value": 1,
"max_value": 9223372036854775807,
"start_value": 1,
"cache_size": 1
}
centia sequence add "rockhall" "my_sequence"
Properties
name(string, required): The name of the sequence.data_type(string): The data type of the sequence. Valid types aresmallint,integer, andbigint. Default isbigint.increment_by(integer): Specifies which value is added to the current sequence value to create a new value. A positive value will make an ascending sequence, a negative one a descending sequence. Default is 1.min_value(integer): Determines the minimum value a sequence can generate.max_value(integer): Determines the maximum value for the sequence.start_value(integer): The initial value of the sequence.cache_size(integer): Specifies how many sequence numbers should be preallocated and stored in memory for faster access. Default is 1.owned_by(string): Associates the sequence with a specific table column, so that if that column (or its whole table) is deleted, the sequence will be automatically deleted as well. The format isschema.table.column.
Get sequence
You can either get a single sequence or a collection of sequences.
- Web App
- HTTP
- CLI
All sequences
GET https://api.centia.io/api/v4/schemas/rockhall/sequences HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
Specific sequence
GET https://api.centia.io/api/v4/schemas/rockhall/sequences/my_sequence HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
Multiple sequences
GET https://api.centia.io/api/v4/schemas/rockhall/sequences/my_sequence,another_sequence HTTP/1.1
Accept: application/json; charset=utf-8
Authorization: Bearer abc123
centia sequence get "rockhall" "my_sequence"
A sequence object looks like this:
{
"name": "my_sequence",
"data_type": "bigint",
"increment_by": 1,
"min_value": 1,
"max_value": 9223372036854775807,
"start_value": 1,
"cache_size": 1,
"owned_by": "public.my_table.id"
}
Update sequence
You can update a sequence by using the PATCH method.
- Web App
- HTTP
PATCH https://api.centia.io/api/v4/schemas/rockhall/sequences/my_sequence HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"increment_by": 2
}
Delete sequence
- Web App
- HTTP
- CLI
DELETE https://api.centia.io/api/v4/schemas/rockhall/sequences/my_sequence HTTP/1.1
Authorization: Bearer abc123
centia sequence drop "rockhall" "my_sequence"