Re: [SQL] Using Ltree For Hierarchical Structures

2013-02-26 Thread Don Parris
On Tue, Feb 26, 2013 at 2:30 PM, Igor Neyman wrote: > > > From: Don Parris [mailto:parri...@gmail.com] > Sent: Tuesday, February 26, 2013 1:23 PM > To: Misa Simic > Cc: Igor Neyman; pgsql-sql@postgresql.org > Subject: Re: [SQL] Using Ltree For Hierarchical Structures &

Re: [SQL] Using Ltree For Hierarchical Structures

2013-02-26 Thread Don Parris
ows with amounts: 1 000 000 > > > (though I am not sure what u meant by: "2-table design using ltree", and with CTE there are 2 tables... Categories and Transactions: just in categories instead of ltree datatype, is integer datatype: parent_id) > > Many thanks, > > Misa >

[SQL] Using Ltree For Hierarchical Structures

2013-02-24 Thread Don Parris
Hi all, With many thanks to Misa and others who helped out with my question about working with hierarchical data, I have now written a blog post on how I implemented the ltree module to solve my problem. http://dcparris.net/2013/02/24/using-ltree-hierarchical-postgresql/ Frankly, if you work wit

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

2013-02-23 Thread Don Parris
help! On Sat, Feb 23, 2013 at 3:13 PM, Ben Morrow wrote: > 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 un

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 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-22 Thread Don Parris
need to keep the category structure in a separate table: Category (category_id, path) Anyway, thanks for suggesting ltree. On Fri, Feb 22, 2013 at 7:15 PM, Don Parris wrote: > Hi Misa, > > I decided to try out ltree, and have made some progress with it. If I > understand correc

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

2013-02-22 Thread Don Parris
n Fri, Feb 22, 2013 at 4:00 AM, Misa Simic wrote: > 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 Frida

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
similar problem with a hierarchical structure for an organization > structure. Another thing you might try is to create a separate CTE for each > category and then aggregate the individual CTEs. > > ** ** > > ** ** > > *From:* pgsql-sql-ow...@postgresql.org [mailto: > pgsql-s

[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

Re: [SQL] Stuck Up In My Own Category Tree

2011-08-11 Thread Don Parris
On Thu, Aug 11, 2011 at 12:48, Edward W. Rouse wrote: > How about SELECT cat_name, sum(amount) AS "amount" FROM category, > trans_details WHERE category_cat_id in (select cat_id from category where > lineage ~ ‘^1’) > > ** ** > > Where the in clause is basically, the cat_id where lineage start

[SQL] Stuck Up In My Own Category Tree

2011-08-11 Thread Don Parris
Hi all, Note: I'm happy to read howtos, tutorials, archived messages - I just haven't found anything that addresses this yet. I found a related topic on the novice list, but my post got no response there. I've been struggling with this for about a week now and need to figure out a solution. Hec