Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 0C9A7133798E for ; Sun, 1 May 2011 16:52:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 12981-06 for ; Sun, 1 May 2011 19:52:11 +0000 (UTC) X-Greylist: delayed 00:06:41.021946 by SQLgrey-1.7.6 Received: from mail.kracon.dk (kracon.net [81.7.185.66]) by mail.postgresql.org (Postfix) with ESMTP id 3F8671336FA7 for ; Sun, 1 May 2011 16:52:09 -0300 (ADT) Received: (qmail 9750 invoked from network); 1 May 2011 19:47:30 -0000 Received: from unknown (HELO ?127.0.0.1?) (127.0.0.1) by localhost with SMTP; 1 May 2011 19:47:30 -0000 Message-ID: <4DBDB854.1010400@krap.dk> Date: Sun, 01 May 2011 21:45:24 +0200 From: Svenne Krap User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110430 Lightning/1.0b3pre Thunderbird/3.1.10 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Multiple recursive part possible? Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/1 X-Sequence-Number: 35285 Hi. I just tried to make a query that traverses a tree upwards to locate the root and then downwards to locate all branches on PGSQL 9.0. The two recursive parts seems to do the right thing each on its own, but together i get an error... ERROR: syntax error at or near "with recursive" LINE 6: with recursive uppath as ( The query in question is with recursive downpath as ( select id , id as bottom, 0 as level from organisation union all select o.id,bottom, level + 1 from organisation o inner join downpath as dp on (dp.id = o.parent) ), with recursive uppath as ( select id, id as top, parent, 0::integer as level from organisation union all select o.id, p.top, o.parent, level + 1 as level from organisation o inner join uppath p on (p.parent = o.id) ) select * from downpath where bottom = (select id from uppath where top = 9 and parent is null); It seems like multiple recursive parts are disallowed (or unhandled). Is there any way to do that query, or do I have to move it out from the database? Or perhaps wrap the "uppath" part in a function (i would prefer not to)? There doesn't seem to be any mentioning of only one recursive part in the docs (at least, I can't find it). I know that is is going to be an expensive query, but I really need all of the tree from the root (parent is null) and downwards... and there is only going to be a couple of 10.000 rows ever (much fewer the first years) Svenne