Re: Learning about WITH RECURSIVE

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Learning about WITH RECURSIVE
Date: 2009-11-04 22:27:14
Message-ID: 396486430911041427q3a0c9518v9c999a34290798ed@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Nov 4, 2009 at 2:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Richard Broersma <richard(dot)broersma(at)gmail(dot)com> writes:
>> Can anyone one explain why a "WITH RECURSIVE" query has the same
>> results regardless whether UNION or UNION ALL is specified?
>
> Well, if the rows are all different anyway, UNION isn't going to
> eliminate any ...

Actually I'm still confused. I must me missing something. When I
manually following the directions of:
http://www.postgresql.org/docs/8.4/interactive/queries-with.html

I get the following when I try:

WITH RECURSIVE t(n) AS (
VALUES (1)
UNION ALL
SELECT n+1 FROM t WHERE n < 100
)
SELECT sum(n) FROM t;

(1) --initial non-recursive working table

(1) UA (2) = (1,2) --new(1) working table

(1,2) UA (2,3) = (1,2,2,3) --new(2) working table

(1,2,2,3) UA (2,3,3,4) = (1,2,2,2,3,3,3,4) --new(3) working table

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2009-11-05 00:04:01 Re: Learning about WITH RECURSIVE
Previous Message Richard Broersma 2009-11-04 22:17:00 Re: Learning about WITH RECURSIVE