Subject RE: [firebird-support] Re: trigger on system table
Author Alan McDonald
> > 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
> > ^
> >
> > But this doesn't work, as if NEW.fields on a system table were not
> > populated :o(
> >
> > Any Idea ?
>
> Quite a novel approach. Unfortunately, even if you do get it to work,
> gbak will not backup triggers etc on the system tables, so your work
> would be lost every time you restored the database.
>
> Adam

unless, as part of you restore procedure, you run a script against the
database to reinstate the triggers. I notice that some backup/restore
utilities have a slot for post resotre scripts..
Alan