Subject Re: [firebird-support] trigger on system table
Author Dany M
legrand_legrand_63 wrote:
> Hello,
> I'm trying to port a PostgreSQL application to FB.
>
> PG as the following Autoincrement syntax:
>
> Create table A (id SERIAL not null, ... , primary key(id));
>
> I have created a domain SERIAL as integer, and a trigger on
> rdb$relation_fields to create the usual sequence and trigger on table
> A to emulate autoincrement feature as follow:
>
> SET TERM ^ ;
>
> CREATE TRIGGER RDB$RELATION_FIELDS_AI0 FOR RDB$RELATION_FIELDS
> ACTIVE AFTER INSERT POSITION 0
> AS
> begin
> if (NEW.rdb$field_source='SERIAL') then
> begin
> execute statement 'CREATE GENERATOR
> '||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_SEQ';
> execute statement 'CREATE TRIGGER
> '||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_TRIG FOR
> '||NEW.rdb$relation_name||'
> ACTIVE BEFORE INSERT POSITION 0
> AS
> BEGIN
> IF (NEW.'||new.rdb$field_name||' IS NULL) THEN
> NEW.'||NEW.rdb$field_name||' =
> GEN_ID('||NEW.rdb$relation_name||'_'||NEW.rdb$field_name||'_SEQ, 1);
> END';
> end
>
> end
> ^
>

Interesting idea! If get some time over (probably wore diapers when that
happened last time) I'll explore the possibilities. And the pitfalls :)

/Dany