Re: Trigger on Update - Mailing list pgsql-general

From mark reid
Subject Re: Trigger on Update
Date
Msg-id 42D7FD8A.7060809@markreid.org
Whole thread Raw
In response to Trigger on Update  (<sunithab@travelpost.com>)
List pgsql-general
Hi,

Change it to a "BEFORE UPDATE" trigger, and set NEW.updated_date := now();

Otherwise each update produces another update produces another update....

-Mark.

sunithab@travelpost.com wrote:

> Can anybody help me creating a trigger on update trigger with update
> statement as below.
>
> This trigger fires after update on a table called note  to update the
> updated_date field.
>
> But when the table is updated the trigger is firing recursively.
>
> Anybody know what is the syntax I have to use in update statement.
>
>
>
> CREATE TRIGGER "trg_update_note_updated_date" AFTER UPDATE
> ON "property"."note" FOR EACH ROW
> EXECUTE PROCEDURE "property"."update_note_updated_date_trg"();
>
>
> CREATE OR REPLACE FUNCTION "property"."update_note_updated_date_trg"
> () RETURNS trigger AS
> $body$
> begin
>   /* New function body */
>        UPDATE property.note SET updated_date=CURRENT_DATE
>        WHERE note_id = NEW. note_id;
>     return null;
> end;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;


pgsql-general by date:

Previous
From: "Scott cox"
Date:
Subject: (Win32 Postgres) Slow to Connect first - OK afterwards
Next
From: Janning Vygen
Date:
Subject: Re: PLPGSQL how to get transaction isolation level info