8.8. Functions for Sequences (Generators)

8.8.1. GEN_ID()

Increments a sequence (generator) value and returns its new value

Result typeBIGINT — dialect 2 and 3 INTEGER — dialect 1

Syntax

GEN_ID([seq-schema <period>] sequence-name, step)

Table 8.80. GEN_ID Function Parameters
ParameterDescription

seq-schema

Schema of the sequence. If not specified, the sequence will be located on the search path.

sequence-name

Identifier name of the sequence (generator)

step

An integer expression of the increment

If step equals 0, the function will leave the value of the generator unchanged and return its current value.

The SQL-compliant NEXT VALUE FOR syntax is preferred, except when an increment other than the configured increment of the sequence is needed.

🛑
Warning

If the value of the step parameter is less than zero, it will decrease the value of the generator. You should be cautious with such manipulations in the database, as they could compromise data integrity (meaning, subsequent insert statements could fail due to generating of duplicate id values).

8.8.1.1. GEN_ID Example

new.rec_id = gen_id(gen_recnum, 1);

See alsoNEXT VALUE FOR, CREATE SEQUENCE (GENERATOR)