Re: automatic update

From: Richard Huxton <dev(at)archonet(dot)com>
To: Alessandro GARDICH <gremlin(at)gremlin(dot)it>, pgsql-general(at)postgresql(dot)org
Subject: Re: automatic update
Date: 2003-09-04 18:21:38
Message-ID: 200309041921.38089.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 02 September 2003 09:34, Alessandro GARDICH wrote:
> Hi to all ...
>
> I'm looking to a way to auto update some fields of a row when other
> fileds are updated.
>
> the table structure are simple,
>
> CREATE TABLE param (
> id int4 PRIMARY KEY,
> val int4,
> ts timestam(3) DEFAULT CURRENT_TIMESTAMP
> );
>
> so when a new entry are insert ts areautomatically update,
> but i would make the same on update ...
[snip]
> I try with a RULE but obtain only a loop, seem RULE aren't good to make
> such things, modify a statment on the same table it's related :(
>
> i look for a trigger but I suppose the same problem arise ...

No - a trigger is what you want. A rule is basically a macro - it transforms
the query, so you can end up with a loop.
If you use a BEFORE UPDATE trigger, you could update NEW.ts to always be up to
date.

Look for my "PostgreSQL Notes" on http://techdocs.postgresql.org/ - there's an
example of this in there somewhere (a bit out of date, but still should be
valid). Probably also looking for the "PostgreSQL cookbook" on the same site.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2003-09-04 18:25:43 Re: pg_autovacuum
Previous Message Jenny - 2003-09-04 18:21:05 Re: [HACKERS] tablelevel and rowlevel locks