Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFhiG-0002Ts-TW for pgsql-docs@arkaria.postgresql.org; Wed, 02 Oct 2019 16:42:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFhhG-0002NI-O5 for pgsql-docs@arkaria.postgresql.org; Wed, 02 Oct 2019 16:41:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFhhG-0002N9-Gs for pgsql-docs@lists.postgresql.org; Wed, 02 Oct 2019 16:41:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFhhE-0002Mn-8P for pgsql-docs@lists.postgresql.org; Wed, 02 Oct 2019 16:41:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x92GfihN009804; Wed, 2 Oct 2019 12:41:45 -0400 From: Tom Lane To: ceharris@vt.edu cc: pgsql-docs@lists.postgresql.org Subject: Re: WITH RECURSIVE (Documentation section 7.8.1) Note In-reply-to: <157002368762.1131.16941475162203318675@wrigleys.postgresql.org> References: <157002368762.1131.16941475162203318675@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Wed, 02 Oct 2019 13:41:27 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9802.1570034504.1@sss.pgh.pa.us> Date: Wed, 02 Oct 2019 12:41:44 -0400 Message-ID: <9803.1570034504@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Doc comments form writes: > In section 7.8.1, the author comments "Note: Strictly speaking, this process > is iteration not recursion, but RECURSIVE is the terminology chosen by the > SQL standards committee." I think I'm to blame for that wording. > Example: R_2 = F(F(R_0)) > Example: R_5 = F(F(F(F(F(R_0)))) > This is textbook recursion, not just some folly of the ANSI standards > committee as suggested by the note in the text. No, it isn't. F() is being applied repeatedly (iteratively). If F() called itself internally, that would be recursion. Another way to look at this is that control of whether the repetition is finished is external to the function/query. If the stop condition were part of the query logic, it'd be more sensible to think of it as recursion, IMO. regards, tom lane