Subject Re: [firebird-support] Complex generators?
Author Florian Hector
> Is there a (nice) way of implementing this behaviour? My ideal case
> would be without using generators, because the TYPE field is also
> dynamic (and CREATE GENERATOR doesn't work inside a trigger, also...)

Create Trigger ADD_ID for MyTable
active before insert position 0
Declare Variable ID Integer;
Select Max(id) from MyTable WHERE TYPE=NEW.TYPE into :ID;
NEW.ID = :ID + 1;

I take it that you are aware of the possible problems that can bring. But if you create a unique
index on Type+ID, the server doesn't let you insert rows with the same combination of Type and ID.