Subject Complex generators?
Author ivoras
i have data that is strucured something like this:
TYPE | ID
-------------
AB 1
AB 2
AB 3
CD 1
CD 2
AB 4
(ID field grows from 1 up, for a single TYPE value), and I'm having
problems implementing data entry in the database. I was thinking of
using a autincrement-type trigger like this:

CREATE TRIGGER ... BEGIN
genname = 'GEN_' || new.type;
new.id = gen_id(:genname, 1);
END

The problem is, the database doesn't like it, and complains of a
syntax error at the gen_id() call. I've tried "SELECT gen_id
(:genname,1) INTO somevar" but it doesn't work.

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...)