Subject Re: Complex generators?
Author ivoras
--- In firebird-support@yahoogroups.com, "Florian Hector"
> Create Trigger ADD_ID for MyTable
> active before insert position 0
> as
> Declare Variable ID Integer;
> begin
> Select Max(id) from MyTable WHERE TYPE=NEW.TYPE into :ID;
> NEW.ID = :ID + 1;
> end
>
> 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.

Yes, that was my first solution, and it fails when there are
concurrent users. TYPE+ID is the primary key.

Maybe there's a way to execute code on commit that would atomicaly
update the ID field?