Re: Updates thru view - Mailing list pgsql-general

From Tom Lane
Subject Re: Updates thru view
Date
Msg-id 13795.1014066920@sss.pgh.pa.us
Whole thread Raw
In response to Updates thru view  ("Rajshekar" <riyer@kc.rr.com>)
List pgsql-general
"Rajshekar" <riyer@kc.rr.com> writes:
> create rule rule_update AS on update to shek_view
>         where old.age = 24
>         do  update shek_tab set age = new.age where old.age = 24 ;

Try

create rule rule_update AS on update to shek_view
        where old.age = 24
        do  update shek_tab set age = new.age where age = old.age;

Your form of the rule reduces to
    update shek_tab set age = new.age where true;
which unsurprisingly updates all rows of the table.

I do not exactly see the point of the conditional rule, either.
Why not just

create rule rule_update AS on update to shek_view
        do  update shek_tab set age = new.age where age = old.age;

The view already restricts visibility of rows, you do not need to
do it twice more in the rules.

            regards, tom lane

pgsql-general by date:

Previous
From: wsheldah@lexmark.com
Date:
Subject: Re: Sum of events over an interval; how?
Next
From: "Gregory Wood"
Date:
Subject: Re: at time zone question in pl/pgSQL