found a way to update a table with data from another one - Mailing list pgsql-sql

From Patrick JACQUOT
Subject found a way to update a table with data from another one
Date
Msg-id 3843BDFD.4EF1BACE@anpe.fr
Whole thread Raw
Responses Re: [SQL] found a way to update a table with data from another one  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi everybody
I've read a quite old posting about the impossibility of updating a
view.
e.g.

Let t1 (Id, balance) and t2 (id, amount) be two tables

DEFINE VIEW U AS SELECT balance, amount FROM t1, t2 WHERE t1.id=t2.id;
UPDATE U SET balance=balance+amount

without writing a rule

I found a simpler way to do the job I wanted done

UPDATE t1 SET  balance = balance+t2.amount WHERE EXISTS (SELECT *
FROM t2 WHERE t2.id = t1.id)

DOES WORK PROPERLY.




pgsql-sql by date:

Previous
From: Thilo Mezger
Date:
Subject: unixtime -> datetime
Next
From: "Emils Klotins"
Date:
Subject: Addendum: PG6.5.3: CASE w. diff THEN types -- prob with Linux(?)