Subject Re: [firebird-support] Problem calling set generator...
Author Svein Erling Tysvaer
Helen Borrie wrote:
> select gen_id(GEN_PREFS,(coalesce((select max(PREF_SN) from
> WHATEVER),0))) from rdb$database

That should work OK if GEN_PREFS is 0 at the start. If not the GEN_PREFS
generator is increased by the max value rather than set to the max value.

A more general solution would be

select gen_id(GEN_PREFS,(coalesce((select max(PREF_SN) from
WHATEVER),0) - gen_id(GEN_PREFS, 0))) from rdb$database

which should set it to the max value regardless of the starting point of
GEN_PREFS (though if other users change GEN_PREFS or add to WHATEVER
while you do this, you risk 'duplicate or missing' values).

Set