X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CCA20475C8B for ; Wed, 12 Feb 2003 15:45:44 -0500 (EST) Received: from lerami.lerctr.org (lerami.lerctr.org [207.158.72.11]) by postgresql.org (Postfix) with ESMTP id E845A475C45 for ; Wed, 12 Feb 2003 15:45:43 -0500 (EST) Received: from lerlaptop.iadfw.net (lerlaptop.iadfw.net [206.66.13.21]) (authenticated bits=0) by lerami.lerctr.org (8.12.7/8.12.7/20030207) with ESMTP id h1CKjgxE015825; Wed, 12 Feb 2003 14:45:42 -0600 (CST) Date: Wed, 12 Feb 2003 14:45:42 -0600 From: Larry Rosenman To: Daniel Jaenecke , PostgreSQL sql Subject: Re: timestamp Message-ID: <322940000.1045082742@lerlaptop.iadfw.net> In-Reply-To: <20030212094615.5f02ce2b.daniel.jaenecke@smaxs.de> References: <20030212094615.5f02ce2b.daniel.jaenecke@smaxs.de> X-Mailer: Mulberry/3.0.1 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: by amavisd-milter (http://amavis.org/) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/260 X-Sequence-Number: 11658 You want a trigger. Similar to the following: CREATE FUNCTION "netblock_date_change" () RETURNS opaque AS 'DECLARE BEGIN new.last_update_at = cast(now() as timestamp(0)); new.last_update_by = current_user; return new; END;' LANGUAGE 'plpgsql'; CREATE TRIGGER "netblock_change" BEFORE INSERT OR UPDATE ON "networks" FOR EACH ROW EXECUTE PROCEDURE "netblock_date_change" (); --On Wednesday, February 12, 2003 09:46:15 +0100 Daniel Jaenecke wrote: > Hi! > > I am rather new to PostGreSQL, having mainly used MySQL until now. > MySQL has a column type TIMESTAMP[1] which holds - as expected - a > timestamp, but additionally this timestamp is being updated automatically > on any UPDATE or INSERT operation. > > Since this is a quite handy feature to keep track of latest changes I > would like to create such a behavior for my PostGres tables too. But > since I have no idea how to do it I would warml welcome any suggestion... > :) > > Thx > dj > > [1] > http://www.mysql.com/doc/en/DATETIME.html > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > -- Larry Rosenman http://www.lerctr.org/~ler Phone: +1 972-414-9812 E-Mail: ler@lerctr.org US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749