Re: Complex Update Queries with Fromlist

From: "Mark Dexter" <MDEXTER(at)dexterchaney(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Complex Update Queries with Fromlist
Date: 2004-10-16 15:11:00
Message-ID: 5E8F9F5B63726C48836757FE673B584E010EE284@dcimail.dexterchaney.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-10-16 16:15:18 Re: Avoiding sequential scans with OR join condition
Previous Message Josh Close 2004-10-16 14:30:32 Re: plpgsql loop not returning value