Subject | trigger on system table |
---|---|
Author | legrand_legrand_63 |
Post date | 2006-09-30T22:18:32Z |
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 ?
Regards
PAscal
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 ?
Regards
PAscal