Обсуждение: Re: Pet Peeves

Поиск
Список
Период
Сортировка

Re: Pet Peeves

От
Dean Rasheed
Дата:
The only one I can see that hasn't already been mentioned

- no ability to define triggers on views

Dean.

_________________________________________________________________
Windows Live Messenger just got better .Video display pics, contact updates & more.
http://www.download.live.com/messenger

Re: Pet Peeves

От
Grzegorz Jaśkiewicz
Дата:
On Sun, Feb 1, 2009 at 10:20 AM, Dean Rasheed <dean_rasheed@hotmail.com> wrote:
> - no ability to define triggers on views
>

maybe because you can't perform insert/delete/update on them ?




--
GJ

Re: Pet Peeves

От
Dean Rasheed
Дата:
>> - no ability to define triggers on views
>>
>
> maybe because you can't perform insert/delete/update on them ?
>

Actually I was thinking the value of triggers on views is precisely
to allow you to perform insert/delete/update on them.

I know you can do this with rules, but there are cases when a
trigger is much more convienent to work with.

Dean.

_________________________________________________________________
Twice the fun—Share photos while you chat with Windows Live Messenger. Learn more.
http://www.microsoft.com/uk/windows/windowslive/products/messenger.aspx

Re: Pet Peeves

От
Grzegorz Jaśkiewicz
Дата:
rules are very very very very rarely useful.
yes, in general - I wouldn't mind to see postgresql implement fully
updatable views.
There's being a very long discussion about that on -hackers, and patch
was even in cvs-head for a bit, but got dropped.
probably enabling triggers for views would be the only way to do it, me thinks.
I don't know how oracle guys got around it.

Re: Pet Peeves

От
Dean Rasheed
Дата:
> rules are very very very very rarely useful.

I wouldn't say that. There are many use cases where rules are
just the thing. Plus they have an added performance benefit
when dealing with multiple rows in a single statement.


> yes, in general - I wouldn't mind to see postgresql implement fully
> updatable views.
> There's being a very long discussion about that on -hackers, and patch
> was even in cvs-head for a bit, but got dropped.
> probably enabling triggers for views would be the only way to do it, me thinks.
> I don't know how oracle guys got around it.

The Oracle solution is quite useful in a large set of cases. The
basic idea is this:

Since a view is arbitrarily complex, there is no way, in general,
that the database can know how to update it. Therefore the concept
of BEFORE or AFTER triggers doesn't really make sense (before or
after something the database can't do anyway).

So instead, the only kind of trigger they allow on a view is an
"INSTEAD OF" row-level trigger. The contract of the trigger function
is that it will be invoked once for each matching row in the view,
and the database will assume that the trigger will do the necessary
work to update that row. Thus Oracle assumes that the number of rows
updated matches the number of times that it invoked the trigger
function.

Apart from this last part, this is like defining a rule

    CREATE RULE my_rule
    AS ON INSERT/UPDATE/DELETE TO my_view
    DO INSTEAD SELECT my_fn(old.*, new.*);

Of course the problem with using a rule in this way is that the
query is rewritten as a SELECT, and the client is told that no
rows were updated. This is where the INSTEAD OF trigger comes in
handy.

Dean.

_________________________________________________________________

Hotmail, Messenger, Photos  and more - all with the new Windows Live. Get started!
http://www.download.live.com/

Re: Pet Peeves

От
Thomas Kellerer
Дата:
Grzegorz Jaśkiewicz wrote on 01.02.2009 13:13:
> probably enabling triggers for views would be the only way to do it, me thinks.
> I don't know how oracle guys got around it.

Oracle *does* have (INSTEAD OF) triggers on views.
(and "simple" views are automatically updateable anyway)

Regards
Thomas