pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Patrick JACQUOT <patrick.jacquot@anpe.fr>
To: pgsql-sql@postgresql.org
Subject: found a way to update a table with data from another one
Date: Tue, 30 Nov 1999 13:07:26 +0100
Message-ID: <3843BDFD.4EF1BACE@anpe.fr> (raw)

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.





view thread (3+ messages)  latest in thread

Message-ID: <3843BDFD.4EF1BACE@anpe.fr>
Permalink:  ../3843BDFD.4EF1BACE@anpe.fr/
Also on:    postgresql.org/message-id/3843BDFD.4EF1BACE@anpe.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: patrick.jacquot@anpe.fr
  Subject: Re: found a way to update a table with data from another one
  In-Reply-To: <3843BDFD.4EF1BACE@anpe.fr>
  References: <3843BDFD.4EF1BACE@anpe.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox