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 3CAE45E46C1 for ; Thu, 26 Aug 2004 03:52:22 -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 17295-09 for ; Thu, 26 Aug 2004 06:52:12 +0000 (GMT) Received: from candice.isogo.co.za (outsmtp.isogo.co.za [196.15.191.4]) by svr1.postgresql.org (Postfix) with ESMTP id 92E2E5E37D0 for ; Thu, 26 Aug 2004 03:52:09 -0300 (ADT) Received: (qmail 25108 invoked by uid 1035); 26 Aug 2004 06:52:06 -0000 Received: from justin@isogo.co.za by mail by uid 89 with qmail-scanner-1.20rc3 (clamscan: 0.60. spamassassin: 2.60. Clear:RC:1:. Processed in 0.090469 secs); 26 Aug 2004 06:52:06 -0000 Received: from host29.isogo.co.za (HELO ?10.5.200.29?) (justin@isogo.co.za@196.15.191.29) by candice.echelon.z with RC4-MD5 encrypted SMTP; 26 Aug 2004 06:52:05 -0000 Message-ID: <412D8893.9070803@isogo.co.za> Date: Thu, 26 Aug 2004 08:52:03 +0200 From: Justin Wyer User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Gary Hoffman , pgsql-php Subject: Re: Mod_date update technique References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed 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/40 X-Sequence-Number: 2928 Gary Hoffman wrote: >I have a column named mod_date on a particular table. It has a default >value of now() which is the create date of the row. However, I want to >update that field with the current timestamp whenever its record is >updated. > >I know how to do this using PHP by including the date() in the data I'm >using to update the record. However, I would like to do this on the >PostgreSQL side of the transaction. I can't figure out how to write a >trigger or other technique to do this. > > A trigger is the correct way. >Simply asked: What is the easiest way to automatically update the mod_date >field when the record is updated? > > Check out the PostgreSQL documentation it is quite comprehensive. http://www.postgresql.org/docs/7.4/interactive/triggers.html Regards Justin