Re: [GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-22 Thread Jonathan Vanasco
On Apr 21, 2010, at 9:38 PM, Glen Parker wrote: Not if qty_requested_available needs to be = qty_available... indeed, i'm an idiot this week. thanks a ton. this really helped me out! -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your

[GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-21 Thread Jonathan Vanasco
I'm trying to write a bit of logic as 1 query, but I can't seem to do it under 2 queries. i'm hoping someone can help the basic premise is that i have an inventory management system , and am trying to update the quantity available in the shopping cart (which is different than the

Re: [GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-21 Thread Tom Lane
Jonathan Vanasco postg...@2xlp.com writes: I'm trying to write a bit of logic as 1 query, but I can't seem to do it under 2 queries. Uh, why can't you just push that CASE expression into the sub-select? UPDATE cart_item SET qty_requested_available = ( SELECT CASE

Re: [GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-21 Thread Glen Parker
Tom Lane wrote: Jonathan Vanasco postg...@2xlp.com writes: I'm trying to write a bit of logic as 1 query, but I can't seem to do it under 2 queries. Uh, why can't you just push that CASE expression into the sub-select? QUERY SNIPPED You might have to qualify qty_requested here to make sure

Re: [GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-21 Thread Jonathan Vanasco
it would be that, but with greatest thank you. that's the exact query i was failing to write ! On Apr 21, 2010, at 8:51 PM, Glen Parker wrote: UPDATE cart_item SET qty_requested_available = least(cart_item.qty_requested, stock.qty_available) FROM stock WHERE cart_item.stock_id =

Re: [GENERAL] trying to write a bit of logic as one query, can't seem to do it under 2

2010-04-21 Thread Glen Parker
Jonathan Vanasco wrote: it would be that, but with greatest Not if qty_requested_available needs to be = qty_available... -Glen -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general