Re: Trigger Question

From: "Jason Lee" <lee(at)iecokc(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Trigger Question
Date: 2007-03-14 15:40:54
Message-ID: 551361601E50574FA29E3435C537A9AD028C91CB@iec04.iecokc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks! That did the trick. I had tried that logic in the function,
but I had always used an AFTER trigger, so it didn't work. Thanks,
again. You've saved my sanity. :)

-----
Jason Lee, SCJP
Senior Software Engineer
http://www.iec-okc.com

> -----Original Message-----
> From: Richard Huxton [mailto:dev(at)archonet(dot)com]
> Sent: Wednesday, March 14, 2007 10:38 AM
> To: Jason Lee
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Trigger Question
>
> 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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2007-03-14 15:42:48 Re: Trigger Question
Previous Message Richard Huxton 2007-03-14 15:37:33 Re: Trigger Question