Re: writable joined view

From: Wiebe Cazemier <halfgaar(at)gmail(dot)com>
To: Sarah Asmaels <sarah(at)spiesonline(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: writable joined view
Date: 2005-10-25 12:07:40
Message-ID: 435E200C.5090405@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-10-25 13:19:07 Re: convert timezone to string ...
Previous Message Magnus Hagander 2005-10-25 11:03:19 Re: convert timezone to string ...