From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Nicolas KOWALSKI <Nicolas(dot)Kowalski(at)imag(dot)fr> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: update in rule |
Date: | 2001-10-17 19:04:40 |
Message-ID: | Pine.BSF.4.21.0110171159030.23020-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin pgsql-sql |
On Wed, 17 Oct 2001, Nicolas KOWALSKI wrote:
> <base>=# \d adresses
> Table "adresses"
> Attribute | Type | Modifier
>
> --------------+------------------------+----------------------------------------
> id | integer | default nextval('adresses_id_seq'::text)
> <snip>
> date_maj | date | default 'NOW'
> Index: adresses_pkey
>
>
> I would like to automatically update the `date_maj' field with the
> current day date whenever an update on a row occurs.
>
> So I created a rule like :
>
> CREATE RULE adresses_date_maj
> AS ON UPDATE TO adresses
> DO UPDATE adresses SET date_maj = 'NOW' ;
>
>
> But as says the documentation, this does not work (circular problem).
>
> Does anyone known how to achieve such a behaviour ?
Use a trigger instead, something like
create function adresses_trigger() returns opaque as '
begin
NEW.date_maj := now();
return NEW;
end;' language 'plpgsql';
create trigger tr before update on adresses for each row execute
procedure adresses_trigger();
From | Date | Subject | |
---|---|---|---|
Next Message | Francisco Solari | 2001-10-17 19:26:54 | "Can't Find any tables, sequences or indexes!" Message |
Previous Message | Stefan Huber | 2001-10-17 17:25:23 | Re: PG on Suse |
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Lebedev | 2001-10-17 22:32:57 | SQL parser and/or optimizer |
Previous Message | Jason Earl | 2001-10-17 18:20:51 | Re: Triggers do not fire |