Skip site navigation (1) Skip section navigation (2)

Re: what are rules for?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Michael Shulman <shulman(at)mathcamp(dot)org>
Cc: Adam Rich <adam(dot)r(at)sbcglobal(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>,pgsql-general(at)postgresql(dot)org
Subject: Re: what are rules for?
Date: 2008-06-24 15:39:06
Message-ID: 20080624153906.GC16068@svana.org (view raw or flat)
Thread:
Lists: pgsql-general
On Tue, Jun 24, 2008 at 10:28:00AM -0500, Michael Shulman wrote:
> I have read the manual.  As I pointed out, the only examples of rules
> in the manual are (1) something which may be better done with a
> trigger, and certainly *can* be done with a trigger, whatever the
> speed considerations may be, and (2) something which doesn't seem to
> work very well, and seemingly (from my PoV) *would* be done better
> with triggers if triggers were allowed in that situation.

It possible that if rules wern't the only way currently to implement
(updateable) views, then they might have been ripped out a long time
ago. Thing is, people like views and there is currently no other way to
do them.

> My question was, what else *can* you do with a rule that you *can't*
> do with a trigger?  Are rules only a way to speed up things that could
> also be done with triggers?

Well, views for one. Rules work by manipulating queries, trigger work
by manipulating tuples. Rules have their problems, but sometimes
they're the only way. Updateable views are the major use case.

FWIW, I wonder if the multiple evaluation problem could be solved by
the WITH patch, since the original rule could be stuffed in a WITH
clause and then the rule applied on top of it.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog(at)svana(dot)org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.

In response to

Responses

pgsql-general by date

Next:From: Tom LaneDate: 2008-06-24 16:08:53
Subject: Re: what are rules for?
Previous:From: Michael ShulmanDate: 2008-06-24 15:28:00
Subject: Re: what are rules for?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group