Re: Generating a query that never returns

From: Florian Pflug <fgp(at)phlo(dot)org>
To: David Fetter <david(at)fetter(dot)org>
Cc: Dave Cramer <pg(at)fastcrypt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Generating a query that never returns
Date: 2011-09-19 16:09:05
Message-ID: 95C0B553-032A-4FA5-868D-D2C2C598D55B@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sep19, 2011, at 17:59 , David Fetter wrote:
> On Mon, Sep 19, 2011 at 05:12:15PM +0200, Florian Pflug wrote:
>> My first try, BTW, was
>>
>> WITH RECURSIVE infinite(value) AS (SELECT 1 UNION ALL SELECT 1)
>> SELECT * FROM infinite
>>
>> but that returns only two rows. I'd have expected it to returns an infinite
>> stream of 1s as well, since the iteration part of the recursive CTE never
>> returns zero rows. The behaviour I get is what I'd have expected if I had
>> written "UNION" instead of "UNION ALL". Am I missing something, or is that
>> a genuine bug?
>
> That's actually the correct behavior. In order to get a recursion (or
> iteration, whichever way you want to look at it), you need to refer to
> the CTE on the right side of the UNION [ALL] (or the INTERSECT [ALL]
> per the SQL standard).

Interesting. Thanks for the explanation!

best regards,
Florian Pflug

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nulik Nol 2011-09-19 16:16:33 Re: CUDA Sorting
Previous Message Kevin Grittner 2011-09-19 16:00:18 Re: Range Types - typo + NULL string constructor