Seaquel
PostgreSQL error code

PostgreSQL error 2200H

2200H is the SQLSTATE PostgreSQL reports for sequence generator limit exceeded, in class 22, Data Exception.

SQLSTATE2200H
Condition namesequence_generator_limit_exceeded
Class22 — Data Exception

Reproduce it, then fix it

A smallint sequence stops at 32,767, and nextval fails once it gets there. Move the sequence to integer or bigint with ALTER SEQUENCE ... AS, and widen the column it feeds. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

CREATE SEQUENCE ticket_no AS smallint START 32766;
SELECT nextval('ticket_no') FROM generate_series(1, 3);
CREATE SEQUENCE ticket_no AS integer START 32766;
SELECT nextval('ticket_no') FROM generate_series(1, 3);

Source: PostgreSQL documentation, Appendix A