Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'clause': 0.07; 'great.': 0.07; 'hierarchical': 0.07; 'subject:How': 0.09; 'part,': 0.09; 'postgres': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python.': 0.11; 'ignore': 0.14; '(say': 0.16; 'appreciated!': 0.16; 'describing': 0.16; 'forth.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reproduce': 0.16; 'row': 0.16; 'traverse': 0.16; 'tutorials.': 0.16; 'variations': 0.16; 'laura': 0.18; 'tree': 0.18; 'do.': 0.22; 'assumes': 0.22; 'skip:n 60': 0.22; 'trying': 0.22; 'decide': 0.23; 'select': 0.23; '(or': 0.23; 'help.': 0.23; 'seems': 0.23; 'wrote': 0.23; 'examples': 0.24; 'header:In-Reply- To:1': 0.24; 'example': 0.26; 'subject:list': 0.26; 'header:X -Complaints-To:1': 0.26; 'least': 0.27; "skip:' 10": 0.28; 'subject:that': 0.29; "i'm": 0.30; 'another': 0.32; 'run': 0.33; 'common': 0.33; 'changing': 0.34; 'equal': 0.34; 'structure': 0.34; 'could': 0.35; 'level': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'child': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'data': 0.39; 'sure': 0.39; 'subject:the': 0.39; 'expressed': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'real': 0.62; 'course': 0.62; 'linked': 0.63; 'to,': 0.63; 'world': 0.64; 'places': 0.64; 'response.': 0.66; 'department.': 0.66; 'organisation': 0.66; 'quantity': 0.66; 'here': 0.66; 'union': 0.67; 'design.': 0.72; 'frank': 0.72; '100%': 0.72; 'deleted?': 0.84; 'post,': 0.84; 'glad': 0.87 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: How to model government organization hierarchies so that the list can expand and compress Date: Sat, 15 Aug 2015 07:59:06 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 197.89.14.139 In-Reply-To: X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3502.922 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3502.922 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439618363 news.xs4all.nl 2835 [2001:888:2000:d::a6]:45573 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95387 "Alex Glaros" wrote in message news:ae4e203d-c664-4388-af0b-41c41d5ec724@googlegroups.com... > Frank, thanks for describing the terminology of what I'm trying to do. > > 1. Do the recursive join Postgres examples you linked to, use a data > structure where the child has the adjoining parent-ID? Examples look > great. I think that their example is very simple - it seems that each level contains one link to the level below, and the level below has no link to the level above (or at least they did not make use of it). The following (untested) example assumes that each row can have multiple children, and each row has a link to its parent called parent_id. WITH RECURSIVE included_parts(part, quantity) AS ( SELECT part, quantity FROM parts WHERE part = 'our_product' UNION ALL SELECT p.part, p.quantity FROM included_parts pr, parts p WHERE p.parent_id = pr.part ) SELECT part, SUM(quantity) as total_quantity FROM included_parts GROUP BY part You will find many variations in various on-line tutorials. For example, you can traverse *up* the tree by changing the WHERE clause to WHERE p.part = pr.parent_id > > 2. Not 100% sure that hierarchical is the perfect solution but will go > with that now. Of course some agencies will be at equal levels; will > ignore for now. > > 3. Could not find Laura's response. Was it deleted? > Laura responded to this in another post, but in case you cannot see that one either, I reproduce it here - """ What I said was, that real agencies are almost never perfectly heirarchical. That's an oversimplification. In the real world Organisation A (say Army) and Organisation B (say Navy) decide they have common interests and make a Joint Department. If you run that department you report to superiors in _both_ organisation A and organisation B, get orders from both places and so on and so forth. You must decide now what you want to do when you run into such departments, because that will greatly influence your design. """ > 4. Solution will expressed in the DB, not Python. > Much appreciated! Glad I could help. Frank