X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3FE32D1B576 for ; Sat, 1 Nov 2003 15:29:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 52404-07 for ; Sat, 1 Nov 2003 11:28:58 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id D3694D1B93D for ; Sat, 1 Nov 2003 11:24:56 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id hA1FOoX6024957; Sat, 1 Nov 2003 10:24:50 -0500 (EST) To: Martin Marques Cc: pgsql-sql@postgresql.org Subject: Re: defaults on updates In-reply-to: <200311011049.17325.martin@bugs.unl.edu.ar> References: <200311011049.17325.martin@bugs.unl.edu.ar> Comments: In-reply-to Martin Marques message dated "Sat, 01 Nov 2003 10:49:17 -0300" Date: Sat, 01 Nov 2003 10:24:49 -0500 Message-ID: <24956.1067700289@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/2 X-Sequence-Number: 15817 Martin Marques writes: > Basically, I have 5 fields, one being a PK (SERIAL), 3 with information, and > the last one a timestamp field that will show the last time the register was > modified (tmodif which has a DEFAULT CURRENT_TIMESTAMP). > Now, eveytime someone modifys any, or all of the 3 information fields, > I want the tmodif field of that register to be set to now(). This is trivial to do with a trigger --- you just need something like NEW.lastmod := now(); RETURN NEW; There's a complete example at the bottom of this page: http://developer.postgresql.org/docs/postgres/plpgsql-trigger.html regards, tom lane