Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

specifying a sequence in create_index()

space_object method space_object:create_index(... [sequence='...' option] ...)

You can use the sequence={sequence-name} (or sequence={sequence-id} or sequence=true) option when creating or altering a primary-key index. The sequence becomes associated with the index, so that the next insert() will put the next generated number into the primary-key field, if the field would otherwise be nil.

The syntax may be any of: BR sequence = {sequence identifier} BR or sequence = {id = {sequence identifier} } BR or sequence = {field = {field number} } BR or sequence = {id = {sequence identifier} , field = {field number} } BR or sequence = true BR or sequence = {}. BR The sequence identifier may be either a number (the sequence id) or a string (the sequence name). The field number may be the ordinal number of any field in the index; default = 1. Examples of all possibilities: sequence = 1 or sequence = 'sequence_name' or sequence = {id = 1} or sequence = {id = 'sequence_name'} or sequence = {id = 1, field = 1} or sequence = {id = 'sequence_name', field = 1} or sequence = {field = 1} or sequence = true or sequence = {}. Notice that the sequence identifier can be omitted, if it is omitted then a new sequence is created automatically with default name = {space-name}_seq. Notice that the field number does not have to be 1, that is, the sequence can be associated with any field in the primary-key index.

For example, if 'Q' is a sequence and 'T' is a new space, then this will work:

tarantool> box.space.T:create_index('Q',{sequence='Q'})---- unique: true  parts:  - type: unsigned    is_nullable: false    fieldno: 1  sequence_id: 8  id: 0  space_id: 514  name: Q  type: TREE...

(Notice that the index now has a sequence_id field.)

And this will work:

tarantool> box.space.T:insert{box.NULL,0}---- [1, 0]...