Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 6FF062E0054 for ; Wed, 7 May 2008 12:28:04 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 74754-05 for ; Wed, 7 May 2008 12:27:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 25F652E002D for ; Wed, 7 May 2008 12:27:57 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m47FRsJh007704; Wed, 7 May 2008 11:27:54 -0400 (EDT) To: CZUCZY Gergely cc: Michael Monnerie , pgsql-admin@postgresql.org Subject: Re: column: on update update? In-reply-to: <20080507165226.7a49557a@twoflower.in.publishing.hu> References: <200805071050.41450@zmi.at> <396486430805070623p360b8eafp39683a287cdb3cc@mail.gmail.com> <200805071649.03336@zmi.at> <20080507165226.7a49557a@twoflower.in.publishing.hu> Comments: In-reply-to CZUCZY Gergely message dated "Wed, 07 May 2008 16:52:26 +0200" Date: Wed, 07 May 2008 11:27:54 -0400 Message-ID: <7703.1210174074@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/53 X-Sequence-Number: 29137 CZUCZY Gergely 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