updating a view - Mailing list pgsql-general

From m.c.wilkins@massey.ac.nz
Subject updating a view
Date
Msg-id 20061215004245.GO20895@massey.ac.nz
Whole thread Raw
Responses Re: updating a view  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
hi,

i would like to allow updates to a view, but pgsql crashes,
presummably from an infinite loop.

i add a rule like so:

   CREATE RULE update_myview AS ON UPDATE TO myview DO INSTEAD SELECT updater(OLD, NEW);

where updater is a plperl function.  the function updater does a few
comparisons off OLD and NEW (to see what has changed) and then, if
necessary, updates one of the tables that makes up myview:

   spi_exec_query("UPDATE mytable SET somefield = somevalue WHERE somecondition");

i can supply the exact code if you wish, but i think the problem lies
more with my approach than the syntax.  what i think is happening is
that the "update mytable set blah blah" statement is executed, but
that causes an update to myview, which causes my rule to run, which
runs updater etc etc.

i'm not sure how to get around this problem though.  how can i do a
UPDATE myview SET foo = bar, and get that to work without using a
rule, that ends up updating a table that updates myview?

thank you for any help!

matt



pgsql-general by date:

Previous
From: Ben
Date:
Subject: Re: a question for the way-back machine
Next
From: Tom Lane
Date:
Subject: Re: updating a view