Re: column: on update update?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: CZUCZY Gergely <gergely(dot)czuczy(at)harmless(dot)hu>
Cc: Michael Monnerie <michael(dot)monnerie(at)it-management(dot)at>, pgsql-admin(at)postgresql(dot)org
Subject: Re: column: on update update?
Date: 2008-05-07 15:27:54
Message-ID: 7703.1210174074@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

CZUCZY Gergely <gergely(dot)czuczy(at)harmless(dot)hu> writes:
> I'd prefer this version:
> CREATE FUNCTION awlupdate RETURNS TRIGGER AS '
> BEGIN
> NEW.lastupdate = now();
> RETURN NEW;
> END' LANGUAGE plpgsql;

> CREATE TRIGGER... the same.

No, the trigger command has to be BEFORE UPDATE not AFTER UPDATE for
this to work. This is definitely the better way though because the
row only gets updated once, not stored and then updated again
(in fact, I think you could get into an infinite loop if an AFTER
UPDATE trigger tries to update the row again).

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message mcravitz 2008-05-07 16:12:00 Can't connect remotely
Previous Message CZUCZY Gergely 2008-05-07 14:52:26 Re: column: on update update?