Skip site navigation (1) Skip section navigation (2)

Re: Mod_date update technique

From: Gene Stevens <gene(at)triplenexus(dot)org>
To: pgsql-php <pgsql-php(at)postgresql(dot)org>
Cc: Gary Hoffman <ghoffman(at)ucsd(dot)edu>
Subject: Re: Mod_date update technique
Date: 2004-08-26 16:28:48
Message-ID: 1093537728.3251.33.camel@philippi.triplenexus.net (view raw or flat)
Thread:
Lists: pgsql-php
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(at)triplenexus(dot)org>
http://gene.triplenexus.org


In response to

pgsql-php by date

Next:From: Gerard SamuelDate: 2004-08-26 20:36:25
Subject: Space requirements (with respect to foriegn languages)
Previous:From: Justin WyerDate: 2004-08-26 06:52:03
Subject: Re: Mod_date update technique

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group