Re: Complex Update Queries with Fromlist - Mailing list pgsql-general

From Mark Dexter
Subject Re: Complex Update Queries with Fromlist
Date
Msg-id 5E8F9F5B63726C48836757FE673B584E010EE284@dcimail.dexterchaney.local
Whole thread Raw
In response to Complex Update Queries with Fromlist  ("Mark Dexter" <MDEXTER@dexterchaney.com>)
List pgsql-general
Thank you.  That works for the simple example I had.

However, I have an additional question about this.  What if I need to do
a LEFT OUTER JOIN in the Fromlist.  For example, this query works but it
requires the orders table to appear twice.

UPDATE orders set requireddate =
  (case when c.city in ('Seattle','Portland') then date(o.OrderDate) + 1

    else date(o.OrderDate) + 2 end)
FROM orders o
LEFT OUTER JOIN customers c on
  o.customerid = c.customerid
  where c.region in ('WA','OR')
 and orders.orderid = o.orderid

Is there some way to do an outer join in the Fromlist back to the main
table being updated without having it appear twice?  Thanks.


pgsql-general by date:

Previous
From: Josh Close
Date:
Subject: Re: plpgsql loop not returning value
Next
From: Tom Lane
Date:
Subject: Re: Avoiding sequential scans with OR join condition