Re: [SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-22 Thread Ian Lawrence Barwick
2013/2/23 Ashwin Jayaprakash : (...) > > Q2: What the best way to check if an HSTORE is empty? Is this it > "array_length(akeys(data), 1) is null"? Just a quick answer to your second question: I suspect it might be more efficient to check your HSTORE column against an empty HSTORE, e.g. WHERE v

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-22 Thread Bryan L Nuse
This works fine: test_ltree=> SELECT path, trans_amt FROM testcat; path | trans_amt -+--- TOP.Transportation.Auto.Fuel| 50.00 TOP.Transportation.Auto.Maintenance | 30.00 TOP.Transportati

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-22 Thread Don Parris
Ok, I managed to accomplish my goal with the ltree: test_ltree=> SELECT subltree(path,0,2), sum(trans_amt) FROM testcat GROUP BY subltree; subltree | sum + TOP.Groceries | 325.00 TOP.Transportation | 180.00 (2 rows) It took a bit of experimenting wi

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-22 Thread Don Parris
Hi Misa, I decided to try out ltree, and have made some progress with it. If I understand correctly how to use it, I simply insert the 'path' column into my table, using ltree as the data type. That eliminates the need for a category table, if I understand correctly. I just need to ensure the c

[SQL] Update HSTORE record and then delete if it is now empty - What is the correct sql?

2013-02-22 Thread Ashwin Jayaprakash
Hi, here's what I'm trying to do: - I have a table that has an HSTORE column - I would like to delete some key-vals from it - If after deleting key-vals, the HSTORE column is empty, I'd like to delete the entire row I have the sample SQL here and the DML I was trying out. I thought a CTE

Re: [SQL] need help

2013-02-22 Thread denero team
Hey, Thanks Russell and all others. The query worked well. I got result what I expected. Thanks again, Dhaval On Fri, Feb 22, 2013 at 4:11 PM, denero team wrote: > Thanks Russell, > > let me check the query. > > On Fri, Feb 22, 2013 at 2:56 PM, Russell Keane > wrote: >>> Or every destinatio

Re: [SQL] need help

2013-02-22 Thread Russell Keane
> Or every destination location of the product in that time period? Ok, I've had another look at this this morning on the assumption you need every location that a product has been in that time period. This also assumes you're getting all the data you're interested in from the product_move table

Re: [SQL] need help

2013-02-22 Thread denero team
Thanks Russell, let me check the query. On Fri, Feb 22, 2013 at 2:56 PM, Russell Keane wrote: >> Or every destination location of the product in that time period? > > Ok, I've had another look at this this morning on the assumption you need > every location that a product has been in that time

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-22 Thread Misa Simic
Hi, Have you considered maybe ltree datatype? http://www.postgresql.org/docs/9.1/static/ltree.html I think it solves a lot of problems in topic Kind regards, Misa On Friday, February 15, 2013, Don Parris wrote: > Hi all, > > I posted to this list some time ago about working with a hiera

Re: [SQL] need help

2013-02-22 Thread Russell Keane
> Sorry, why do you need the joins? > > Best, > Oliver Strictly speaking, for the examples and results given, the joins are pointless when you can get all the info from the 'move' table (but then the problem is like the 'hello world' of SQL) But then the other 2 tables are completely redundant