What is the best way of writing update rule on view with joined tables? - Mailing list pgsql-sql

From cpng@sophos.com (Cornelius Grotjahn)
Subject What is the best way of writing update rule on view with joined tables?
Date
Msg-id 195fde65.0404160943.722481e3@posting.google.com
Whole thread Raw
List pgsql-sql
Please, how can I rewrite the rule below so that it works as intended for this
update:
  update v set ad=0, bd=0 where ad=1;

As it is now, this will change ad but not bd, presumably because when the
rule's first action has updated ad, the "where ad=1" returns 0 rows for the
second action.

I want this because that is the way MS Access puts data into updates' where
clauses and I want updateable forms on joined tables.

  create table a (k integer primary key, ad integer);  create table b (k integer primary key, bd integer);  create view
vas select a.k, ad, bd from a join b on a.k=b.k;  create rule r as on update to v do instead  (     update a set
ad=new.adwhere k=old.k;     update b set bd=new.bd where k=old.k;  );
 
  insert into a values(1,1);  insert into a values(2,2);  insert into b values(1,1);  insert into b values(2,2);


Thank you -- Cornelius


pgsql-sql by date:

Previous
From: Pallav Kalva
Date:
Subject: Querying From two databases
Next
From:
Date:
Subject: ANN: www.SQL-Scripts.Com