Re: update with select - Mailing list pgsql-general

From Jean-Luc Lachance
Subject Re: update with select
Date
Msg-id 3E1E00EF.1444EC0@nsd.ca
Whole thread Raw
In response to update with select  ("Cristóvão B. B. Dalla Costa"<cbraga@bsi.com.br>)
List pgsql-general
Try:


UPDATE product SET price_min = ss.min_price, price_max = ss.max_price
from ( select min( price) as min_price, max( price) as max_price
  FROM subproduct WHERE subproduct.product = $ID) as ss
WHERE id = $ID;



"Cristóvão B. B. Dalla Costa" wrote:
>
> Hi,
>
> Is it possible to rewrite this query to use a single SELECT?
>
> UPDATE product SET
> price_min = (SELECT min (price) FROM subproduct WHERE subproduct.product
> = $ID),
> price_max = (SELECT max (price) FROM subproduct WHERE subproduct.product
> = $ID)
> WHERE id = $ID
>
> Thanks.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

pgsql-general by date:

Previous
From: Feite Brekeveld
Date:
Subject: unsubscribe
Next
From: Michelle Konzack
Date:
Subject: Re: How to backup a postgreSQL of 80 GByte ?