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] 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] 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

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] Summing & Grouping in a Hierarchical Structure

2013-02-21 Thread Alexander Gataric
l.org] On Behalf Of Don Parris Sent: Thursday, February 21, 2013 4:38 AM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Summing & Grouping in a Hierarchical Structure Hi Alexander, I appreciate you taking time to reply to my post. I like the idea of the WITH RECURSIVE query, but... The two

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

2013-02-21 Thread Don Parris
ql-sql-ow...@postgresql.org] On Behalf Of Don Parris > > Sent: Thursday, February 14, 2013 8:58 PM > > To: pgsql-sql@postgresql.org > > Subject: [SQL] Summing & Grouping in a Hierarchical Structure > > > > Hi all, > > I posted to this list some time ago about work

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

2013-02-21 Thread Don Parris
ql-ow...@postgresql.org] *On Behalf Of *Don Parris > *Sent:* Thursday, February 14, 2013 7:58 PM > *To:* pgsql-sql@postgresql.org > *Subject:* [SQL] Summing & Grouping in a Hierarchical Structure > > ** ** > > Hi all, > > I posted to this list some time ago abou

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

2013-02-18 Thread Relyea, Mike
> From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] > On Behalf Of Don Parris > Sent: Thursday, February 14, 2013 8:58 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Summing & Grouping in a Hierarchical Structure > > Hi all, > I poste

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

2013-02-14 Thread Alexander Gataric
TE for each category and then aggregate the individual CTEs. From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Don Parris Sent: Thursday, February 14, 2013 7:58 PM To: pgsql-sql@postgresql.org Subject: [SQL] Summing & Grouping in a Hierarchical

[SQL] Summing & Grouping in a Hierarchical Structure

2013-02-14 Thread Don Parris
Hi all, I posted to this list some time ago about working with a hierarchical category structure. I had great difficulty with my problem and gave up for a time. I recently returned to it and resolved a big part of it. I have one step left to go, but at least I have solved this part. Here is t