SETVAL(sequence_name, next_value, [is_used, [round]])
Set the next value to be returned for a
This function is compatible with PostgreSQL syntax, extended
is_used argument is not given or is 1 or
TRUE, then the next used value will
one after the given value. If
is_used is 0 then the next generated value
will be the given value.
round is used then it will set the
round value for the sequence.
round is not used, it's assumed to be 0.
SEQUENCE tables defined with
CYCLE one should use both
round to define the next value. In this case the
current sequence value is defined to be
SELECT setval('foo', 42); -- Next nextval will return 43 SELECT setval('foo', 42, true); -- Same as above SELECT setval('foo', 42, false); -- Next nextval will return 42
The result returned by
next_value or NULL if the given
round is smaller than the current value.
SETVAL() will not set the
SEQUENCE value to a something that is less than
its current value. This is needed to ensure that
is replication safe. If you want to set the SEQUENCE to a smaller number
use ALTER SEQUENCE.
CYCLE is used, first
round and then
next_value are compared
to see if the value is bigger than the current value.
Internally, in the MariaDB server,
SETVAL() is used to inform
slaves that a
SEQUENCE has changed value. The slave may get
SETVAL() statements out of order, but this is ok as only the
biggest one will have an effect.