found a way to update a table with data from another one

From: Patrick JACQUOT <patrick(dot)jacquot(at)anpe(dot)fr>
To: pgsql-sql(at)postgresql(dot)org
Subject: found a way to update a table with data from another one
Date: 1999-11-30 12:07:26
Message-ID: 3843BDFD.4EF1BACE@anpe.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-11-30 15:22:43 Re: [SQL] found a way to update a table with data from another one
Previous Message Thilo Mezger 1999-11-30 08:07:35 unixtime -> datetime