Re: update help - Mailing list pgsql-sql

From Josh Berkus
Subject Re: update help
Date
Msg-id web-1178595@davinci.ethosmedia.com
Whole thread Raw
In response to Re: update help  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Tom,

> UPDATE t1 SET amount = (select sum(b.amount) from t2 b
> WHERE t1.id = b.id);

Interesting.  I'm used to (not necessarily in PGSQL):

UPDATE t1 SET amount = t2ttl.totalamount
FROM (SELECT sum(amount) as totalamount,    id FROM t2 GROUP BY id) t2ttl
WHERE t1.id = t2.id

Although this is a subselect in the FROM clause, something
we've had trouble with as I recall.

-Josh Berkus


pgsql-sql by date:

Previous
From: Carolyn Lu Wong
Date:
Subject: Re: update help
Next
From: Tom Lane
Date:
Subject: Re: update help