X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 04B305E46E7 for ; Thu, 26 Aug 2004 13:31:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23600-04 for ; Thu, 26 Aug 2004 16:31:20 +0000 (GMT) Received: from rwcrmhc13.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by svr1.postgresql.org (Postfix) with ESMTP id 479D25E37D0 for ; Thu, 26 Aug 2004 13:31:10 -0300 (ADT) Received: from [192.168.1.4] (c-24-8-244-130.client.comcast.net[24.8.244.130]) by comcast.net (rwcrmhc13) with SMTP id <2004082616311601500qds1ne> (Authid: gene.stevens); Thu, 26 Aug 2004 16:31:17 +0000 Subject: Re: Mod_date update technique From: Gene Stevens Reply-To: gene@triplenexus.org To: pgsql-php Cc: Gary Hoffman In-Reply-To: <412D8893.9070803@isogo.co.za> References: <412D8893.9070803@isogo.co.za> Content-Type: text/plain Message-Id: <1093537728.3251.33.camel@philippi.triplenexus.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 26 Aug 2004 10:28:48 -0600 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/41 X-Sequence-Number: 2929 On Thu, 2004-08-26 at 00:52, Justin Wyer wrote: > A trigger is the correct way. > > Check out the PostgreSQL documentation it is quite comprehensive. > http://www.postgresql.org/docs/7.4/interactive/triggers.html Justin is right. What you'll need to do is create a function that modifies that mod_date column and the create a trigger to call it whenever that record is updated. Here's an example that I think might work for you: CREATE FUNCTION my_date_modified() RETURNS trigger AS ' BEGIN NEW.mod_date := ''now''; RETURN NEW; END; ' LANGUAGE plpgsql; CREATE TRIGGER my_date_mod BEFORE INSERT OR UPDATE ON table FOR EACH ROW EXECUTE PROCEDURE my_date_modified(); For this example, you'd need to have the plpgsql language installed on your database if it isn't already: shell> createlang plgsql dbname -- Gene Stevens http://gene.triplenexus.org