Re: Updates on Views?

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Updates on Views?
Date: 2001-03-23 01:14:49
Message-ID: 20010322191449.B13810@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 22, 2001 at 09:48:43PM +0100, Konstantinos Agouros wrote:
> In <Pine(dot)BSF(dot)4(dot)21(dot)0103212025030(dot)38659-100000(at)megazone23(dot)bigpanda(dot)com> sszabo(at)megazone23(dot)bigpanda(dot)com (Stephan Szabo) writes:
> >On 21 Mar 2001, Konstantinos Agouros wrote:
> >> are views in PG read-only or is this possible?

views are read-only -- but interestingly, a view is actually an
empty table with interference-running rules attached. you can
overlay your own 'do instead' rules to effect various
behind-the-scenes inserts and updates...

> >You can make updatable views by making the appropriate rules
> >on the view for handling insert/update/delete (whatever
> >you want).
> Could You give me a hint on where to read up on this?

on my debian system it's mentioned in the postgresql-doc package
at...

% grep -rl INSTEAD /usr/share/doc/postgresql-doc/html
/usr/share/doc/postgresql-doc/html/programmer/rules1139.htm
/usr/share/doc/postgresql-doc/html/programmer/rules978.htm
/usr/share/doc/postgresql-doc/html/user/sql-createrule.htm
/usr/share/doc/postgresql-doc/html/user/syntax.htm

i'd look in USER documentation under CREATE RULE to get started.
(also at postgresql.org user-lounge area)

--

okay, here's a quickie example:

CREATE VIEW who AS
SELECT * from _who;

CREATE RULE
who_insert
AS ON
INSERT TO who
DO INSTEAD
INSERT INTO "_who" (
login,
"password",
hint,
name,
email,
editor,
status,
modified,
created,
id
) VALUES (
NEW.login,
NEW."password",
NEW.hint,
NEW.name,
NEW.email,
NEW.editor,
'U'::bpchar, -- uncertain until confirmed
"timestamp"('now'::text), -- last mod
"timestamp"('now'::text), -- created now
nextval('_who_id_seq'::text)
);
-- all non-mentioned fields from _who are silently
-- ignored (and dropped).

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
-- Isaac Asimov, 'The Genetic Code'

will(at)serensoft(dot)com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Limin Liu 2001-03-23 01:16:50 SPI example does not work for 7.1beta4
Previous Message will trillich 2001-03-23 01:03:55 Re: Extreme Newbie Questions