Re: what are rules for? - Mailing list pgsql-general

From Tom Lane
Subject Re: what are rules for?
Date
Msg-id 18734.1214323733@sss.pgh.pa.us
Whole thread Raw
In response to Re: what are rules for?  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: what are rules for?
List pgsql-general
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Tue, Jun 24, 2008 at 10:28:00AM -0500, Michael Shulman wrote:
>> 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.

To expand on that: it's pretty hard to see how update or delete triggers
on a view would work.  Insert is easy, because if left to its own
devices the system would in fact try to insert a tuple into the view
relation, and that action could fire a trigger which could redirect the
insertion someplace else.  But updates and deletes require a
pre-existing target tuple, and there just aren't any of those in a view
relation.  (Another way to say it is that update/delete require a CTID
column, which a view hasn't got.)

So view update/delete appear to require a transformational-rule kind
of approach instead of an actions-on-physical-tuples kind of approach.

If you've got a better idea we're all ears ...

            regards, tom lane

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: what are rules for?
Next
From: "Ryan Wells"
Date:
Subject: String Encoding Conversion Problem