Triggers

Поиск
Список
Период
Сортировка
От nolan@celery.tssi.com
Тема Triggers
Дата
Msg-id 20030414191323.4502.qmail@celery.tssi.com
обсуждение исходный текст
Ответы Re: Triggers  (Ben Clewett <B.Clewett@roadrunner.uk.com>)
Список 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 по дате отправления:

Предыдущее
От: Ben Clewett
Дата:
Сообщение: Triggers
Следующее
От: "Bryan Encina"
Дата:
Сообщение: Case Statements in Rules?