Re: Trigger Question - Mailing list pgsql-general

From Richard Huxton
Subject Re: Trigger Question
Date
Msg-id 45F816BD.1000501@archonet.com
Whole thread Raw
In response to Trigger Question  ("Jason Lee" <lee@iecokc.com>)
List pgsql-general
Jason Lee wrote:
> I'm trying to write a trigger that updates a date_changed field on a
> record anytime that record is updated.  I have a function written, and
> the trigger created, but everytime I update the record, I get a
> recursion limit error.
[snip]
> declare begin
>     update unit_specification set date_changed = now() from
> unit_specification us where us.id = NEW.id;
>     RETURN NEW;
> end;

Here, just do
   NEW.date_changed = now();
   RETURN NEW;

> With the trigger created with
>
> CREATE TRIGGER update_changed_ts AFTER INSERT OR UPDATE
>    ON unit_specification FOR EACH ROW
>    EXECUTE PROCEDURE public.update_unit_spec_changed_date();

Make this BEFORE insert or update.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: grant permissions to set variable?
Next
From: Hannes Dorbath
Date:
Subject: Re: Statement logging