Re: Why can't I put a BEFORE EACH ROW trigger on a view?

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Webb Sprague <webb(dot)sprague(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Why can't I put a BEFORE EACH ROW trigger on a view?
Date: 2007-02-25 01:20:24
Message-ID: 1172366424l.30468l.9l@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 02/24/2007 06:55:45 PM, Webb Sprague wrote:
> I also think that a view is supposed to be just that -- a *view* of
> underlying data, which in no way modifies the data. I don't know much
> about the design ideas behind SQL, but I think this view of views
> (haha) is an underlying assumption. If you are modifying data when
> you do a select on a view, you are probably not using SQL the way it
> was intended (not that that is a bad thing, but ...)

The postgresql docs say something like: Having lots of views
is the mark of good database design.

That's because views present the same data in various ways,
to different users as each user thinks of the data. In general,
they allow good db design, and in a well designed db will
be incomprensibe to the average user, partly because it contains lots
of foreign keys to manage 1-to-many relationships. If it
makes sense to make a view so the user can see the data
in a form they can understand, then it makes sense to
allow the user to update the same view of the data.

> Postgresql has "rules" which I *think* can rewrite select statements.
> Rules are kind of a pain, but maybe what you want.

You can't rewrite select statments. That's where I started.
Trying to do so turns your table into a view, which then
can't have triggers.

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-02-25 01:48:58 Re: Why can't I put a BEFORE EACH ROW trigger on a view?
Previous Message Karl O. Pinc 2007-02-25 01:15:12 Re: Why can't I put a BEFORE EACH ROW trigger on a view?