Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wN00h-000VNZ-0B for pgsql-hackers@arkaria.postgresql.org; Wed, 13 May 2026 03:11:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wN00f-006xS0-1M for pgsql-hackers@arkaria.postgresql.org; Wed, 13 May 2026 03:11:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wN00f-006xRs-0Q for pgsql-hackers@lists.postgresql.org; Wed, 13 May 2026 03:11:45 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wN00c-00000000KWb-2RDM for pgsql-hackers@postgresql.org; Wed, 13 May 2026 03:11:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=PF0tKy9CCTqa/YVvCD0iKIM4p1F26/KfuPspC+7BNZQ=; b=zzwOtttPIggYXVqhENiNgf0EvB I84c2tA+YeOZVVaWPLtbiOuyRPHNzEJfszJEBbCkROUIRz3oL5MKCivPbz2hkTPVUuQm5VL/Y1clD 3W1ctzJJpSKhar1xpW7C1bOONPF62C+koppfFMmuHmlwwbhv/oecsy16u0UCoG6vn1zJhBtq3yi+k LvU41TMeJrt00rYuv9MECGomWd1HbyAEqK24gx0JTpHC4c5qFUXTML3QLewXwX2XRruvMVFVcSxbF 6Rc0xWbch+QxTLV+M3NmGUyHURiskQ5gX5j1oIs2QJqiiHlXbLZ9nTGYYT3oBWVJx2np1sdXJqX3r nFBoaufQ==; Received: from [2409:11:4120:300:9bb9:7daf:c950:471c] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wN00O-000qBc-0D; Wed, 13 May 2026 03:11:30 +0000 Date: Wed, 13 May 2026 12:11:14 +0900 (JST) Message-Id: <20260513.121114.1783343463509775310.ishii@postgresql.org> To: assam258@gmail.com Cc: zsolt.parragi@percona.com, sjjang112233@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, li.evan.chao@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Row pattern recognition From: Tatsuo Ishii In-Reply-To: References: <20260502.140304.670813149418899420.ishii@postgresql.org> <20260512.150328.1502361632049642572.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:9bb9:7daf:c950:471c (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Henson, Thank you for the patches. I looked into 0013. > diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c > index ccde199319a..3830597bb2b 100644 > --- a/src/backend/parser/parse_cte.c > +++ b/src/backend/parser/parse_cte.c > @@ -96,6 +96,14 @@ static void checkWellFormedRecursion(CteState *cstate); > static bool checkWellFormedRecursionWalker(Node *node, CteState *cstate); > static void checkWellFormedSelectStmt(SelectStmt *stmt, CteState *cstate); > > +/* Recursive-WITH RPR rejection */ > +typedef struct > +{ > + ParseLoc location; /* location of first RPR window, or -1 */ > +} ContainRPRContext; > + > +static bool contain_rpr_walker(Node *node, void *context); > + > > /* > * transformWithClause - > @@ -157,13 +165,31 @@ transformWithClause(ParseState *pstate, WithClause *withClause) > if (withClause->recursive) > { > /* > - * For WITH RECURSIVE, we rearrange the list elements if needed to > - * eliminate forward references. First, build a work array and set up > - * the data structure needed by the tree walkers. I think removing the exiting comment ("For WITH RECURSIVE, we rearrange the list elements...") is not appropriate as this explains subsequent process, which is not changed after the patch. > + * Per ISO/IEC 9075-2:2016 7.17 Syntax Rule 3)e)f), every + * element> in a WITH RECURSIVE clause is "potentially recursive" and > + * shall not contain a . (PostgreSQL does > + * not implement , so only the common syntax > + * needs to be checked.) ISO/IEC 19075-5 6.17.5 (R020) and 4.18.5 > + * (R010) restate the prohibition for CREATE RECURSIVE VIEW, which is > + * rewritten to WITH RECURSIVE by makeRecursiveViewSelect() and so > + * flows through here as well. > */ > CteState cstate; > int i; > > + foreach(lc, withClause->ctes) > + { > + CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); > + ContainRPRContext ctx; > + > + ctx.location = -1; > + if (contain_rpr_walker(cte->ctequery, &ctx)) > + ereport(ERROR, > + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ERRCODE_FEATURE_NOT_SUPPORTED should be ERRCODE_SYNTAX_ERROR instead? IMO ERRCODE_FEATURE_NOT_SUPPORTED is used when the feature is defined by the standard but PostgreSQL just has not implemented yet. In this case the standard disllow RPR in recursive CTE. > + errmsg("cannot use row pattern recognition in a recursive query"), > + parser_errposition(pstate, ctx.location)); > + } > + > cstate.pstate = pstate; > cstate.numitems = list_length(withClause->ctes); > cstate.items = (CteItem *) palloc0(cstate.numitems * sizeof(CteItem)); > @@ -1268,3 +1294,29 @@ checkWellFormedSelectStmt(SelectStmt *stmt, CteState *cstate) > } > } > } Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp