4035
MariaDBERRORNotableSequenceHIGH confidence

Sequence has run out of values

What this means

ER_SEQUENCE_RUN_OUT (4035) is returned when a SEQUENCE object has exhausted all available values in its defined range and CYCLE is not enabled.

How to reproduce
trigger — this will error
trigger — this will error
CREATE SEQUENCE s START WITH 1 MINVALUE 1 MAXVALUE 3 NO CYCLE;
SELECT NEXT VALUE FOR s;  -- 1
SELECT NEXT VALUE FOR s;  -- 2
SELECT NEXT VALUE FOR s;  -- 3
SELECT NEXT VALUE FOR s;  -- ERROR 4035

expected output

ERROR 4035 (HY000): Sequence 's' has run out

Fix

Add CYCLE or extend MAXVALUE

WHEN Values can wrap around or the range needs extending.

Add CYCLE or extend MAXVALUE
-- Allow cycling (reuse values from MINVALUE after exhaustion):
ALTER SEQUENCE s CYCLE;

-- Or extend the range:
ALTER SEQUENCE s MAXVALUE 1000000;

Why this works

CYCLE causes the sequence to restart from MINVALUE after reaching MAXVALUE. Extending MAXVALUE avoids the exhaustion entirely.

What not to do

✕ Use CYCLE on sequences that generate primary key values

Cycling a sequence used for primary keys will produce values that already exist, causing duplicate key errors (1062) unless old rows have been deleted.

Version notes
MariaDB 10.3

SEQUENCE objects are a MariaDB 10.3+ feature. They are not available in MySQL.

Sources
Official documentation ↗

MariaDB — CREATE SEQUENCE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors