Re: column: on update update? [solved]

From: Michael Monnerie <michael(dot)monnerie(at)it-management(dot)at>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: column: on update update? [solved]
Date: 2008-05-08 07:41:03
Message-ID: 200805080941.03990@zmi.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mittwoch, 7. Mai 2008 Tom Lane wrote:
> 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).

OK, here's the final correct syntax (examples missed the () at the
function name):

CREATE FUNCTION awlupdate() RETURNS TRIGGER AS '
BEGIN
NEW.lastupdate = now();
RETURN NEW;
END' LANGUAGE plpgsql;

CREATE TRIGGER awlupdate BEFORE UPDATE ON awl FOR EACH ROW EXECUTE
PROCEDURE awlupdate();

Thanks for your help! It's a bit complex just for an update, but it
works. :-)

mfg zmi
--
// Michael Monnerie, Ing.BSc ----- http://it-management.at
// Tel: 0676/846 914 666 .network.your.ideas.
// PGP Key: "curl -s http://zmi.at/zmi.asc | gpg --import"
// Fingerprint: AC19 F9D5 36ED CD8A EF38 500E CE14 91F7 1C12 09B4
// Keyserver: www.keyserver.net Key-ID: 1C1209B4

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Guillaume Lelarge 2008-05-08 07:53:49 Re: Converting from 7.4.19 To 8.3.1 & want to use autovacuum
Previous Message Bruce Momjian 2008-05-08 02:24:13 Re: postgresql in FreeBSD jails: proposal