From: | nolan(at)celery(dot)tssi(dot)com |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Triggers |
Date: | 2003-04-14 19:13:22 |
Message-ID: | 20030414191323.4502.qmail@celery.tssi.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Bryan Encina | 2003-04-14 21:16:12 | Case Statements in Rules? |
Previous Message | Andrew Sullivan | 2003-04-14 18:08:39 | Re: Remote logging in postgres |