Generate the next value and return it.
The generation algorithm is simple:
- If this is the first time, then return the STARTS WITH value.
- If the previous value plus the INCREMENT value is less than the
MINIMUM value or greater than the MAXIMUM value, that is “overflow”,
so either raise an error (if
false) or return the MAXIMUM value (if
step< 0) or return the MINIMUM value (if
If there was no error, then save the returned result, it is now the “previous value”.
For example, suppose sequence ‘S’ has:
- previous value = -2.
box.sequence.S:next()returns -5 because -2 + (-3) == -5.
box.sequence.S:next()again returns -1 because -5 + (-3) < -6, which is overflow, causing cycle, and
This function requires a ‘write’ privilege on the sequence.
This function should not be used in “cross-engine” transactions (transactions which use both the memtx and the vinyl storage engines).
To see what the previous value was, without changing it, you can select from the _sequence_data system space.