Re: Update rule

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: Secrétariat <ets(at)rolland-fr(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Update rule
Date: 2004-12-30 18:08:20
Message-ID: opsjt1z6jqcq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


You get infinite recursion because your ON UPDATE rule does another
UPDATE which of course calls the rule ; so no, it's not a bug ; also your
UPDATE updates almost the whole table so it won't do what you had in mind
in the first place. You should rather change the NEW row in your update so
that NEW.dmodtar = current_date and NEW.umodtar = current_user. Which
means you'll rather be using a trigger for this. Read the docs on CREATE
TRIGGER and see the examples, I think there's one which looks like what
you want.

> Hello !
>
> I wish to create a rule to write in records who and when modified them.
> I wrote :
> CREATE OR REPLACE RULE tarif_upd AS
> ON UPDATE TO tarifs
> DO ALSO
> UPDATE tarifs
> SET dmodtar = current_date, umodtar = current_user
> WHERE dmodtar <> current_date AND umodtar <> current_user ;
> But I obtain an infinite recursion !
> It seems not using the where clause ?
> Is it a bug ?
> How can I workaround ...
>
> Best regards.
> Luc

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2004-12-30 18:15:32 Re: pg_dump and pgpool
Previous Message Secrétariat 2004-12-30 17:35:23 Update rule