Subject Re: Insert Trigger which makes an Update if pk allready there possible?
Author kaczy27
Hi,

> In a trigger, if you can't solve the problem by handling
> it, you *want* the exception to end the operation. That's the
point of
> triggers.
but that's what I want to achieve - solve a problem of existing key.

Will this work as a before insert trigger?

/* trigger fire on insert row */
/* if there is already a record with this key sum the value fields */
/* known bug: if new or old value is null, the sum will be null */

select 1 from "table" where "pk" = new.pk into :pk_var;
if (:pk_var = 1) then begin
select "value" from "table" where "pk" = new.pk into :value_var;
new.value = new.value + value_var;
delete from "table" where "pk" = new.pk;
end
/* proceed with insert operation */

>
> ./heLen

CUIN Kaczy