Re: update in rule

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: update in rule
Дата
Msg-id Pine.BSF.4.21.0110171159030.23020-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на update in rule  (Nicolas KOWALSKI <Nicolas.Kowalski@imag.fr>)
Ответы Re: update in rule
Re: update in rule
Список pgsql-admin
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();



В списке pgsql-admin по дате отправления:

Предыдущее
От: Stefan Huber
Дата:
Сообщение: Re: PG on Suse
Следующее
От: Allan Engelhardt
Дата:
Сообщение: Re: Automatically starting postmaster after system crash