Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 01E2C634162 for ; Wed, 4 Nov 2009 18:27:27 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 52117-08 for ; Wed, 4 Nov 2009 22:27:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f186.google.com (mail-iw0-f186.google.com [209.85.223.186]) by mail.postgresql.org (Postfix) with ESMTP id 387556326D1 for ; Wed, 4 Nov 2009 18:27:16 -0400 (AST) Received: by iwn16 with SMTP id 16so5115273iwn.29 for ; Wed, 04 Nov 2009 14:27:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=2cNHRp4p8cuSSHIqUuW/cS683FVt+8zmE9vdeHF+1wg=; b=vJxELMjHDVTFVui38ZfAd9EBhilf7Rp2toAoySIIi9LJNsq+/XAn0SwzSkBSolRpW+ Fo67YDAhMh1rgc2CfVGhQ5JbaX4G5649V6K7oaqLSEj1q3WDPNnInabe3Fp5RsHdp+/w ioKWVJgFbYamhpimAmHjWJVIDFhWaLT4YsOb0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=tW+SZE1xCS56UenYXMPwLJzl955ZXyLDg4hOzvbQQs31046An1jZR1Fe9X32oo+k34 XB8YjubE/KutreTXlT0Ry8IoSzpeyTiMXu+5V2VbqoimasYL1e9WSGcRLPcUVJSFFSlZ UrD2Tb2Dmzklftd51tQNxYj9cFHwsgC3TSkac= MIME-Version: 1.0 Received: by 10.231.59.12 with SMTP id j12mr3253907ibh.48.1257373634741; Wed, 04 Nov 2009 14:27:14 -0800 (PST) In-Reply-To: <27333.1257372664@sss.pgh.pa.us> References: <396486430911041403u639c750bn488ada60822448c0@mail.gmail.com> <27333.1257372664@sss.pgh.pa.us> Date: Wed, 4 Nov 2009 14:27:14 -0800 Message-ID: <396486430911041427q3a0c9518v9c999a34290798ed@mail.gmail.com> Subject: Re: Learning about WITH RECURSIVE From: Richard Broersma To: Tom Lane Cc: sql pgsql Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.5 tagged_above=-10 required=5 tests=AWL=0.099, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/23 X-Sequence-Number: 33374 On Wed, Nov 4, 2009 at 2:11 PM, Tom Lane wrote: > Richard Broersma 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