From: | Larry Rosenman <ler(at)lerctr(dot)org> |
---|---|
To: | Daniel Jaenecke <daniel(dot)jaenecke(at)smaxs(dot)de>, PostgreSQL sql <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: timestamp |
Date: | 2003-02-12 20:45:42 |
Message-ID: | 322940000.1045082742@lerlaptop.iadfw.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(dot)jaenecke(at)smaxs(dot)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(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
From | Date | Subject | |
---|---|---|---|
Next Message | Nicholas Allen | 2003-02-12 20:53:08 | Re: How do you select from a table until a condition is met? |
Previous Message | Bruno Wolff III | 2003-02-12 20:41:09 | Re: null foreign key column |