8.8. Functions for Sequences (Generators)
8.8.1. GEN_ID()
Available in
DSQL, ESQL, PSQL
Syntax
GEN_ID (generator-name, step)
Parameter | Description |
---|---|
generator-name | Name of a generator (sequence) that exists. If it has been defined in double quotes with a case-sensitive identifier, it must be used in the same form unless the name is all upper-case. |
step | An integer expression |
Result type
BIGINT
Description
Increments a generator or sequence and returns its new value. If step equals 0, the function will leave the value of the generator unchanged and return its current value.
- From Firebird 2.0 onward, the SQL-compliant
NEXT VALUE FOR
syntax is preferred, except when an increment other than 1 is needed.
Example
new.rec_id = gen_id(gen_recnum, 1);
If the value of the step parameter is less than zero, it will decrease the value of the generator. Attention! You should be extremely cautious with such manipulations in the database, as they could compromise data integrity. |
See also