Subject | Re: Insert Trigger which makes an Update if pk allready there possible? |
---|---|
Author | kaczy27 |
Post date | 2004-08-20T15:29:38Z |
Hi,
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 */
> In a trigger, if you can't solve the problem by handlingpoint of
> it, you *want* the exception to end the operation. That's the
> 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 */
>CUIN Kaczy
> ./heLen