WITH RECURSIVE (Documentation section 7.8.1) Note

From: PG Doc comments form <noreply(at)postgresql(dot)org>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Cc: ceharris(at)vt(dot)edu
Subject: WITH RECURSIVE (Documentation section 7.8.1) Note
Date: 2019-10-02 13:41:27
Message-ID: 157002368762.1131.16941475162203318675@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/9.4/queries-with.html
Description:

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."

This comment is not helpful (at best) and misleading (at worst).

The "process" which is the subject of the comment is based on the
implementation of WITH RECURSIVE in PostgreSQL -- the implementation happens
to execute a sequence of queries and a temporary table, and one could
arguably describe this as iteration.

However, the use of the term RECURSIVE in the syntax, refers not to any
particular implementation, but to an observation that WITH RECURSIVE is
effectively an example of a recursively defined function in set-theoretic
terms. Consider the first of the UNIONed statements to produce a row set
R_0. Consider the second of the UNIONed statements to be function F that
produces a row set R_k = F(R_k-1). (The underscore is used here to denote a
subscript).

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.

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2019-10-02 15:58:52 Pls mention ERROR: 2D000: cannot commit while a subtransaction is active on this page
Previous Message Magnus Hagander 2019-10-02 13:16:28 Re: I'm surprised to see the word master here