From: Christopher Browne <cbbrowne@acm.org>
To: pgsql-sql@postgresql.org
Subject: Re: A tricky sql-query...
Date: Sun, 02 Nov 2003 20:40:15 -0500
Message-ID: <m3he1mcjr4.fsf@wolfe.cbbrowne.com> (raw)
References: <bn6uhi$jp3$1@news.hub.org>
<slrnbqb94a.2417.mark@tanagra.summersault.com>
Quoth mark@summersault.com (Mark Stosberg):
> On 2003-10-22, Timo <siroco@suomi24.fi> wrote:
>>
>> You can't have any recursion in an pure sql-query, can you?
>
> It depends on how you think of recursion, I'd say. You join on the same
> table a number of times, by giving it a different alias each time. You
> have to manually specify (or generate with application code) all these
> aliases and joins, though. Sometimes people use this technique to
> implement tree structures in SQL.
There is apparently an SQL 1999 feature that expressly supports
recursion.
WITH RECURSIVE
Q1 AS SELECT ... FROM ... WHERE ...
Q2 AS SELECT ... FROM ... WHERE ...
SELECT ... FROM Q1, Q2 WHERE ...
See example here...
<http://www.dbaiien.ac.at/proj/dlv/sql/.tuw;
There is presumably some work ongoing; support for WITH RECURSIVE is
on the TODO list, and has been discussed before...
http://archives.postgresql.org/pgsql-hackers/2003-05/msg00657.php
--
output = reverse("gro.mca" "@" "enworbbc")
http://www.ntlug.org/~cbbrowne/linuxdistributions.html
"Listen, strange women, lyin' in ponds, distributin' swords, is no
basis for a system of government. Supreme executive power derives
itself from a mandate from the masses, not from some farcical aquatic
ceremony." -- Monty Python and the Holy Grail
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: cbbrowne@acm.org
Subject: Re: A tricky sql-query...
In-Reply-To: <m3he1mcjr4.fsf@wolfe.cbbrowne.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox