Triggers - Mailing list pgsql-novice

From nolan@celery.tssi.com
Subject Triggers
Date
Msg-id 20030414191323.4502.qmail@celery.tssi.com
Whole thread Raw
Responses Re: Triggers  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
List pgsql-novice
> CREATE FUNCTION t_dec_item_summary ()
> RETURNS trigger
> AS '
>    BEGIN
>      update orders set
>        item_count = item_count - 1
>      WHERE code = OLD.orders;
>      RETURN OLD;
>    END;
> ' language 'plpgsql';

I think your problem may be that you are returning OLD instead of NEW,
I think that substitutes the old values for the new ones which cancels
the impact of an update.  (I'm not sure what it'd do on a delete,
you may need an OLD there, in which case you will need to vary the
return statement based on TG_OP.)

I'm also not sure of your logic.  Why decrement the counter on an
update?  Do you have a separate trigger to increment it on an insert?
By using TG_OP you can probably combine all three actions into one
trigger, personally I find that neater than having multiple triggers.
--
Mike Nolan


pgsql-novice by date:

Previous
From: Ben Clewett
Date:
Subject: Triggers
Next
From: "Bryan Encina"
Date:
Subject: Case Statements in Rules?