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

2013-02-23 Thread Don Parris
Misa & Ben, Thanks. I guess I overlooked that in the docs. I did see the part about the 65KB. I don't see my labels getting overly long. I'll be fine with Herbs_Spices. I make up the labels myself, so it's really no big deal. Alexander & Bryan - Many thanks for the help! On Sat, Feb 23, 2

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

2013-02-23 Thread Ben Morrow
Quoth parri...@gmail.com (Don Parris): > > Is it possible to use spaces in the ltree path, like so: > TOP.Groceries.Food.Herbs & Spices > > Or do the elements of the path have to use underscores and dashes? >From the docs: | A label is a sequence of alphanumeric characters and underscores (for

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

2013-02-23 Thread Misa Simic
Hi Don, To be honest with you - i dont know - but think it is not... We use it to solve the problem with hierarchy relations - but it is nowhere "visible" to users in the app... Our internal rule is to use ids in ltree structure to solve many others problems, actually to easy get, actual categor

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

2013-02-23 Thread Ashwin Jayaprakash
Thanks Tom. I'll try it out soon.

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

2013-02-23 Thread Ashwin Jayaprakash
Thanks, that makes sense. On Fri, Feb 22, 2013 at 9:53 PM, Ian Lawrence Barwick wrote: > 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

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

2013-02-23 Thread Don Parris
Misa, Is it possible to use spaces in the ltree path, like so: TOP.Groceries.Food.Herbs & Spices Or do the elements of the path have to use underscores and dashes? On Sat, Feb 23, 2013 at 7:19 AM, Misa Simic wrote: > Hi Don, > > Yes, its better to use it in category table... > > Bryan, how ma

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

2013-02-23 Thread Don Parris
Hi Bryan, The detailed category listing is dead simple to create: SELECT cat_id, cat_name, sum(amount) FROM category, line-item GROUP BY cat_name, cat_id; But... as you say, the result is a LOT of numbers over the course of 160-ish categories of all levels. Which is why it is so important to be

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

2013-02-23 Thread Bryan L Nuse
> That said, now that I have finally gotten the chance to try ltree, I think I > like it a lot. Hello Don, Yes, after looking at ltree --which I had not done before-- I have to agree with Misa that it looks like the right solution for your problem. That is not to say that "brute force" SQL

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

2013-02-23 Thread Don Parris
Hi Bryan, My current (maybe about to be deprecated now) category table is a recursive table that I join on the line-item table. Your suggestion of using a table for each level of category is probably a bit easier to manage in some respects. However, as you pointed out, it becomes unwieldy when v

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

2013-02-23 Thread Misa Simic
Hi Don, Yes, its better to use it in category table... Bryan, how many levels there will be - we dont know... With one table - and ltree is solved all cases... To add new subcategory user just picks the parent category... So it is easy to add chain ring to gear... As category... In another tra

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

2013-02-23 Thread Tom Lane
Ashwin Jayaprakash writes: > 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 > with update_qry as( > update up