Re: writable joined view - Mailing list pgsql-sql

From Wiebe Cazemier
Subject Re: writable joined view
Date
Msg-id 435E200C.5090405@gmail.com
Whole thread Raw
In response to writable joined view  (Sarah Asmaels <sarah@spiesonline.net>)
List pgsql-sql
Sarah Asmaels wrote:
> Hi!
> 
> I have one table referencing an object in another table through an ID,
> and a view joining those tables on the ID. I want to create rules to
> rewrite updates/deletes/inserts on the joined view to act on the real
> tables. Can you give me some pointers? The documentation has only
> examples for views depending on single tables.
> 
> Thank you,
> 
> Sarah

Is there any difference in multi or single table view? When you create a rule, 
you have access to NEW and/or OLD, which will contain all the fields your view 
has. You can then do something like this:

CREATE RULE insert_rule AS ON INSERT TO your_view DO INSTEAD (INSERT INTO table1 (name) VALUES (NEW.name);INSERT INTO
table2(favorite_color) VALUES (NEW.favorite_color);
 
);

Or is there something I'm not understanding about your request, or perhaps rules 
in general?


pgsql-sql by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: convert timezone to string ...
Next
From: Tom Lane
Date:
Subject: Re: convert timezone to string ...