Re: Help on update that subselects other records in table, uses joins - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Help on update that subselects other records in table, uses joins
Date
Msg-id 200310290942.57584.josh@agliodbs.com
Whole thread Raw
In response to Help on update that subselects other records in table, uses joins  (Jeff Kowalczyk <jtk@yahoo.com>)
Responses Re: Help on update that subselects other records in table, uses joins
List pgsql-sql
Jeff,

> UPDATE ordercharges INNER JOIN orders ON
> orders.orderid = ordercharges.orderid
> SET orderchargeasbilled =

You may only UPDATE one table at a time, you can't update a JOIN.  So when 
selecting from another table to filter or calculate your update, the form is:

UPDATE orderchanges 
SET orderchargesbilled = {expression}
FROM orders
WHERE orders.orderid = ordercharges.orderidAND etc.

Second, your value expression for the update is a subselect which includes a 
select on the table and field you are updating!  This is a recursive loop and 
a very bad idea; gods only know what you'll end up with.

I suggest Joe Conway's "SQL for Smarties"  or "SQL Queries for Mere Mortals" 
from another author.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco


pgsql-sql by date:

Previous
From: OpenGis
Date:
Subject: Re: Link Oracle tables in Postgre
Next
From: Greg Stark
Date:
Subject: Re: Table versions