tarantool

Tarantool - AUTOINCREMENT equivalent?


During my first steps with Tarantool I am wondering how to do basic things.

Imagine that I am storing the following registers:

s:insert(1,'{"name": "foo name", "phone": "foo phone"}')
s:insert(2,'{"name": "barname", "phone": "bar phone"}')

Is there something similar to autoincrement primary key in SQL databases so I do not need to enumerate the indexes?

Something like not specifying the primary index at all in Tarantool 1.6.

Thanks,


Solution

  • There is a (deprecated) auto_increment function, which you could use like:box.space.bigspace:auto_increment{'Fld#1', 'Fld#2'}.

    Fld#1 and Fld#2 are the contents to place into a new tuple. See here. Since Tarantool 1.7.5, it is recommended to use sequences though, which are interesting in that they let you specify how you'd like your keys generated. Basically once you set up a sequence, you assign it to a space, and it autoincrements whenever you add a new tuple.