Re: Bug #772: Rewriting on multi-record updates is - Mailing list pgsql-bugs

From Rod Taylor
Subject Re: Bug #772: Rewriting on multi-record updates is
Date
Msg-id 1032396113.47165.12.camel@jester
Whole thread Raw
List pgsql-bugs
On Wed, 2002-09-18 at 17:08, Anto Prijosoesilo wrote:
> I was afraid that you're going to say that (use
> triggers) :-).
>
> I'm trying _not_ to use triggers because rules are
> more maintainable than triggers here in my
> environment. At least with rules someone who knows SQL
> would be able to maintain it with just a little extra
> training.
>
> The PostgreSQL 7.2 Reference Manual, in the section
> for CREATE RULE seems to imply that the rules are
> executed per row of the target table. I'm referring to
> paragraph 2 of the description.

Read the last paragraph of that section:

 It is important to realize that a rule is really a query transformation
mechanism, or query macro. The entire query is processed to convert it
into a series of queries that include the rule actions. This occurs
before evaluation of the query starts. So, conditional rules are handled
by adding the rule condition to the WHERE clause of the action(s)
derived from the rule. The above description of a rule as an operation
that executes for each row is thus somewhat misleading. If you actually
want an operation that fires independently for each physical row, you
probably want to use a trigger not a rule. Rules are most useful for
situations that call for transforming entire queries independently of
the specific data being handled.


Not that the description is obvious, but it's there.  Perhaps you know
of a better way (place) to state this?

--
  Rod Taylor

pgsql-bugs by date:

Previous
From: Sean Chittenden
Date:
Subject: Re: SET autocommit begins transaction?
Next
From: Bruce Momjian
Date:
Subject: Re: SET autocommit begins transaction?