From: Gene Stevens <gene@triplenexus.org>
To: pgsql-php <pgsql-php@postgresql.org>
Cc: Gary Hoffman <ghoffman@ucsd.edu>
Subject: Re: Mod_date update technique
Date: Thu, 26 Aug 2004 10:28:48 -0600
Message-ID: <1093537728.3251.33.camel@philippi.triplenexus.net> (raw)
In-Reply-To: <412D8893.9070803@isogo.co.za>
References: <fc.00249f0e00f7ab7700249f0e00f7ab77.f7abac@irpsmail.ucsd.edu>
<412D8893.9070803@isogo.co.za>
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 <gene@triplenexus.org>
http://gene.triplenexus.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: gene@triplenexus.org, ghoffman@ucsd.edu
Subject: Re: Mod_date update technique
In-Reply-To: <1093537728.3251.33.camel@philippi.triplenexus.net>
References: <fc.00249f0e00f7ab7700249f0e00f7ab77.f7abac@irpsmail.ucsd.edu> <412D8893.9070803@isogo.co.za> <1093537728.3251.33.camel@philippi.triplenexus.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox