8.8. Functions for Sequences (Generators)
8.8.1. GEN_ID()
Available inDSQL, ESQL, PSQL
Result typeBIGINT
Syntax
|
GEN_ID (generator-name, step)
GEN_ID
Function ParametersParameter | 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 |
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.
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.
8.8.1.1. GEN_ID
Example
|new.rec_id = gen_id(gen_recnum, 1);