logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Re: views and rules: msg#00253

db.postgresql.novice

Subject: Re: views and rules

Michiel Lange <michiel@xxxxxxxxxxxxxx> writes:
> I cannot create rules on views

Sure you can. Here's a trivial example. This lets a user of view
"bar" see a subset of rows in "foo", update only some fields of
those rows, and not insert or delete anything:

regression=# create table foo (f1 int, f2 text);
CREATE TABLE
regression=# create view bar as select * from foo where f1 < 100;
CREATE VIEW
regression=# create rule bar_update as on update to bar do instead
regression-# update foo set f2 = new.f2 where f1 = old.f1;
CREATE RULE
regression=# insert into foo values(1,'ok');
INSERT 547779 1
regression=# insert into foo values(101, 'u cant see me');
INSERT 547780 1
regression=# select * from bar;
f1 | f2
----+----
1 | ok
(1 row)

regression=# update bar set f1 = f1+1, f2 = f2 || ' added';
UPDATE 1
regression=# select * from bar;
f1 | f2
----+----------
1 | ok added
(1 row)

regression=# select * from foo;
f1 | f2
-----+---------------
101 | u cant see me
1 | ok added
(2 rows)


If you wanted to allow inserts or deletes via the view, you'd write
additional rules for that.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo