Re: Why can't I put a BEFORE EACH ROW trigger on a view? - Mailing list pgsql-general

From Karl O. Pinc
Subject Re: Why can't I put a BEFORE EACH ROW trigger on a view?
Date
Msg-id 1172373699l.30468l.14l@mofo
Whole thread Raw
In response to Re: Why can't I put a BEFORE EACH ROW trigger on a view?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 02/24/2007 08:55:40 PM, Tom Lane wrote:
> "Karl O. Pinc" <kop@meme.com> writes:
>
> NEW and OLD only include the user-visible columns.  I'm not sure that
> that's sufficient.  If you assume that the view exposes a primary key
> for each of its underlying tables, then you could use the pkey values
> to find and update a row in the underlying table(s), but this is not
> exactly guaranteeing that you're updating the same row that the view
> query saw initially.  And what if you don't want the view to expose
> the pkey?

These are INSERT, UPDATE, and DELETEs, so why not get rid of
the SELECT column criteria and modify the query plan to
come up with a SELECT * ?  In other words, why not expose everything
to the trigger?  You'd only be doing this if there wasn't
otherwise a rule for, say, UPDATE, on the view anyhow.

Oh.  You'd have to keep any non-columm expressions that the view
exposes.  NEW sounds easy, but I don't know about OLD.
Somehow the rules are doing something for OLD now.

You'd have to come up with column name
conventions (or some syntax)
for NEW and OLD to handle conflicts should some
joined tables have non-unique column names.  (The ones exposed
by the view already have names.)
I don't know the right way to approach
this problem but it feels tractable.  (To somebody who's
very unlikely to be writing the code.  FYI, you're like the
Pg-General-List-Code-Angel.)


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


pgsql-general by date:

Previous
From: "Karl O. Pinc"
Date:
Subject: Re: Why can't I put a BEFORE EACH ROW trigger on a view?
Next
From: Dave Page
Date:
Subject: Re: Ruby on Rails for PostgreSQL