pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Larry Rosenman <ler@lerctr.org>
To: Daniel Jaenecke <daniel.jaenecke@smaxs.de>
To: PostgreSQL sql <pgsql-sql@postgresql.org>
Subject: Re: timestamp
Date: Wed, 12 Feb 2003 14:45:42 -0600
Message-ID: <322940000.1045082742@lerlaptop.iadfw.net> (raw)
In-Reply-To: <20030212094615.5f02ce2b.daniel.jaenecke@smaxs.de>
References: <20030212094615.5f02ce2b.daniel.jaenecke@smaxs.de>

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 
<daniel.jaenecke@smaxs.de> 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






view thread (13+ messages)  latest in thread

Message-ID: <322940000.1045082742@lerlaptop.iadfw.net>
Permalink:  ../322940000.1045082742@lerlaptop.iadfw.net/
Also on:    postgresql.org/message-id/322940000.1045082742@lerlaptop.iadfw.net

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ler@lerctr.org, daniel.jaenecke@smaxs.de
  Subject: Re: timestamp
  In-Reply-To: <322940000.1045082742@lerlaptop.iadfw.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