Skip site navigation (1) Skip section navigation (2)

Re: Recursive SQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: andy_turk(at)hotmail(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Recursive SQL
Date: 2000-04-20 03:47:08
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
"Andy Turk" <andy_turk(at)hotmail(dot)com> writes:
> I was reading Graeme Birchall's SQL Cookbook at 
> and came across an *amazing* technique called recursive SQL.

Interesting, but I think Birchall has confused some very peculiar 
(and incorrect) implementation-specific behavior of DB2 with SQL.
This is not SQL.

Leaving aside a minor quibble about whether the WITH syntax he shows
is valid (it's surely not SQL92, although it might be SQL3 if SQL3 ever
becomes a standard), the really fundamental problem is that you cannot
have a SELECT query that inspects its own output.  He claims that in
SELECT foo UNION SELECT bar, the "bar" select will somehow see the
output of the "foo" select --- and not only that, but will be
recursively invoked to see its *own* outputs.  I do not believe that
any such interpretation can be extracted from the SQL standard.
If SQL worked that way, then simple commands like
	UPDATE foo SET x = 42 WHERE y = 44
would be infinite loops, because they'd see the new tuples produced
by their own action and try to update those, leading to more new
tuples, etc etc.

He's built a large intellectual edifice on a DB2 bug.

			regards, tom lane

In response to


pgsql-sql by date

Next:From: Larry ganga giriDate: 2000-04-20 04:07:44
Subject: How to do this in pgsql?
Previous:From: Lincoln YeohDate: 2000-04-20 02:59:07
Subject: Re: Connecting website with SQL-database.....

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group