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 1vzRoy-0010vG-04 for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 04:02:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzRow-00DWl9-1K for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 04:02:18 +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 1vzRow-00DWl0-0D for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 04:02:18 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzRou-00000001ja1-1cGD for pgsql-hackers@postgresql.org; Mon, 09 Mar 2026 04:02:18 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-3599019ae92so4132319a91.0 for ; Sun, 08 Mar 2026 21:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773028935; cv=none; d=google.com; s=arc-20240605; b=ZxHhGX36vT56u5xrOlLs5lzyFw7pBSjbVDW9WKMYe1ML1419XhEf+oGi6hjq7RrtBh trQWS8eCcLOHnIFvSiq48/XbLjrDyC8iYNoH4Rj4ixqKJBvkAJuyX7WLiKSOMaVmIn5L XHzYL44/zGgn2vhTm+mOxRbeLbgeOJdmUf5qqUS5xeCe+zdt/I3WzBBt2Xm5QaDgNQt/ vd20hG+La8A4QNxsKEj6QiqnkfisBBBTLf8uT0Eo4OSAcjEzDmHgHk4DbG0DdCZjwxZp UsWZBHSmyjoQupulKF5HqAewJ8GoU5PVUmpJNybQF8W0i4mOFbe9tZ2xkYHrYT/hbNHg Kpbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:dkim-signature; bh=jlXVcHSav6wmlZL9xv4O6Zv4rL3X5iURgNcKkW1ilyU=; fh=Sq+eiJxRvlpK7jJY4MkN9BsjTcUNkBr0K+h14zvza0Y=; b=K90Ltmo6EzpZNWWMFFuMWr1G6WBw6DmrjBScuIlY2V3JA2cKCbHgHzikuRtLnBwAG2 vArZqE+mlAhgBDkhGR+NGBng/1V7SQIel6TTTQ6tsLSf049H3WpqLJhGtkVx9H3DXFBU xxAlrD5cnX0lifoggyYPg6OxIXZ3/C9cpWxqHJF+VHn+kbYR73N5HTT97i6vxMk0wCLa WIgYeeMo+YClfqOPXl7mXCNDbDDAayJWll5+b2ZSugtT8fgvlGec/S7ETnKiHsoxhyJ3 MUhmym4ONy23rVkAMqYH0gYfR+I0S3xmPh7ZgvL/3/ossac/U2qwmgpb7ex7QcdaX/98 aRAA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773028935; x=1773633735; darn=postgresql.org; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jlXVcHSav6wmlZL9xv4O6Zv4rL3X5iURgNcKkW1ilyU=; b=DuJ8EXsSkIzIagL+QrbeMcLth3CHtQtpC0nLSSfxmF3OAnXxo4iVm7VyPA6dw1zUHi OoeJEiiW4cEPxETxSRUO+4WrJoXyTJszNXAkxFaMq/IjIRspXqWcGr29I6v7GfWenWJ5 udwzdb7TqE+SEyOA1OolQx91E7QZdxPu00Ra1NdfKnen06mYR1Y1XM8w7YYPiwIGcLpm F8NuMLhmHMe2udO2JJKbWpJyXMay7ZvgL1jzVqh+WJayvSQIGSCZ1N/VlJooPRBAnJV/ kchEzIn4oHxlyyA7x1f3TXTeLuZfYCNNY5M2bOtLWfVIZRF5lMW29iKQe/Lafl96T8BY dW8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773028935; x=1773633735; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jlXVcHSav6wmlZL9xv4O6Zv4rL3X5iURgNcKkW1ilyU=; b=GyLKRdmv3v1J7LYFyRVKPVDJLbyUjbM9Zk869u2E9MghXSg1gchrTA6aPgjnMfxSX+ YFMkYKzuwZrKirb6Ej4QhOtru0GIf+xJmwiWdEIaWIp7ebeJmPP1fiz9fYPogmcp4gA6 TzvzHYGEuRUXxXssoMAUI6Oq3oVsdiOFjDll5CtXRRQmjZlZd/QTIFv1xDj+LGwoD3V3 DL41h0Qx0//Xs3sJ70LZGGcwPuzqLkhNJ2JVxpYdFBp6jgM8smIt0b2S8JM2FoP6BiCv stpmcf1860Nqz1Nk7/I3NhIMipHZ+ZhrClsXY6dJTw2TSvcMATgW9PrD/ostEV1vpjPr arCg== X-Forwarded-Encrypted: i=1; AJvYcCULNY+tM1EJbhZIzuOpESwJ5wtp3rjrNYa+sOJKEU6x/xvF8KjRjqdYd43DY2TWJ38aaZqYfTRV1vd0SRjO@postgresql.org X-Gm-Message-State: AOJu0Yzu/eGWH0BqTZTNfzU04Q0Mm58XbwQMjPhrObchFYjMWMGZ2G6H hrKeiN6Q7uFXUn/UJ4AQkT2T7FziFzp1nQNjAh8QZJC0ea7EBHytpgAzUamtJqYaCXcnE9wIavL MJEtg8PN47izq0VkUzFp1MDaEhNwj5tY= X-Gm-Gg: ATEYQzwGkCLDO+8ZqZ7VDWMPfzFu3jbNr92jg8BzMNYvxj7ocBh1/r9gjXtryvdsjzY /HYNaoi02hSWaTmqYNsANGQ6i5JMI94Xa0u2ysxx+/NX5zrEnWlnsNMr/m/kXO4xOFRXLUFCjwU fHyhM6EpjJnJbV2cRahCSi+qkGv+MhtyCESnCPA6kVE7ujvveomdhAGdOa/gkIxtv/ONeTxUGiL RL4V+h6p/cUa+81feqZCkYIideY70ozheIE5p8NdBlfu06dYhtCnL+T7JS0MQi+uolSKzfgSkD/ 2PBPqOYnCnUafTtCqcUh3/8DUeB27ehMZvGSFaM= X-Received: by 2002:a17:90a:dfcf:b0:356:83b2:539b with SMTP id 98e67ed59e1d1-359be329e14mr8768299a91.32.1773028934391; Sun, 08 Mar 2026 21:02:14 -0700 (PDT) MIME-Version: 1.0 References: <20260306.153837.2137322608184587391.ishii@postgresql.org> <20260308.084722.1574081784704713701.ishii@postgresql.org> <20260309.120802.1845076903520202301.ishii@postgresql.org> In-Reply-To: <20260309.120802.1845076903520202301.ishii@postgresql.org> Reply-To: assam258@gmail.com From: Henson Choi Date: Mon, 9 Mar 2026 13:02:02 +0900 X-Gm-Features: AaiRm53WwTDeCrYJZVBZcpJISKJJs2fkrdSvksC27ZOZ1UE4533z-Rt1ZMUFfsw Message-ID: Subject: Re: Row pattern recognition To: Tatsuo Ishii Cc: sjjang112233@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, pgsql-hackers@postgresql.org Content-Type: multipart/alternative; boundary="000000000000cf9b6a064c8f77af" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cf9b6a064c8f77af Content-Type: text/plain; charset="UTF-8" Hi Tatsuo, > > 10/12 Walk DEFINE clause in window tree traversal [new] > > A newly discovered issue: nodeFuncs.c was not visiting the > > DEFINE clause in expression_tree_walker, query_tree_walker, > > and their mutator counterparts. The demonstrated case is SQL > > function inlining: a SQL function with a parameter used in > > DEFINE (e.g., DEFINE A AS v > $1) would fail to substitute > > the actual argument, producing wrong results. > > Excellnt findings! BTW, I realized that we cannot use $1 of function > in PATTERN clause like: A{$1}. > > ERROR: 42601: syntax error at or near "$1" > LINE 10: PATTERN (A{$1}) > ^ > LOCATION: scanner_yyerror, scan.l:1211 > > Should we document somewhere? > The PATTERN quantifier {n} only accepts Iconst (integer literal) in the grammar. When a host variable or function parameter is used (e.g., A{$1}), the user gets a generic syntax error. Oracle accepts broader syntax and validates later, producing an error at a later stage rather than a syntax error at parse time. PostgreSQL itself already has precedent for this pattern -- in fact, within the same window clause, frame offset (ROWS/RANGE/GROUPS) accepts a_expr in the grammar and then rejects variables in parse analysis via transformFrameOffset() -> checkExprIsVarFree(). I'd lean against documenting this. The SQL standard already defines the quantifier bound as , so there is nothing beyond the standard to call out, and documenting what is *not* allowed tends to raise questions that wouldn't otherwise occur to users. Rather, I think accepting a broader grammar and validating later would be the more appropriate response, producing a descriptive error like: "argument of bounded quantifier must be an integer literal" I can either include this in the current patch set or handle it as a separate follow-up after the main series is committed. What do you think? Regards, Henson --000000000000cf9b6a064c8f77af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi T= atsuo,
=C2=A0
>=C2=A0 =C2=A010/12=C2=A0 Walk DEFINE clause in window tree traversa= l=C2=A0 [new]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A newly discovered issue: nodeFuncs.= c was not visiting the
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DEFINE clause in expression_tree_wal= ker, query_tree_walker,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 and their mutator counterparts. The = demonstrated case is SQL
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 function inlining: a SQL function wi= th a parameter used in
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DEFINE (e.g., DEFINE A AS v > $1)= would fail to substitute
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 the actual argument, producing wrong= results.

Excellnt findings!=C2=A0 BTW, I realized that we cannot use $1 of function<= br> in PATTERN clause like: A{$1}.

ERROR:=C2=A0 42601: syntax error at or near "$1"
LINE 10:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0PATTERN (A{$1})
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 ^
LOCATION:=C2=A0 scanner_yyerror, scan.l:1211

Should we document somewhere?

The PATTERN qu= antifier {n} only accepts Iconst (integer literal) in the
grammar.=C2=A0= When a host variable or function parameter is used (e.g.,
A{$1}), the u= ser gets a generic syntax error.

Oracle accepts broader syntax and v= alidates later, producing an error
at a later stage rather than a syntax error at parse time.
PostgreSQL itself already has precedent for this pattern -- in fact,within the same window clause, frame offset (ROWS/RANGE/GROUPS) acceptsa_expr in the grammar and then rejects variables in parse analysis viatransformFrameOffset() -> checkExprIsVarFree().

I'd lean aga= inst documenting this.=C2=A0 The SQL standard already defines
the quanti= fier bound as <unsigned integer literal>, so there is nothing
beyo= nd the standard to call out, and documenting what is *not* allowed
tends= to raise questions that wouldn't otherwise occur to users.

Rath= er, I think accepting a broader grammar and validating later would
be th= e more appropriate response, producing a descriptive error like:

=C2= =A0 "argument of bounded quantifier must be an integer literal"
I can either include this in the current patch set or handle it as a<= br>separate follow-up after the main series is committed.=C2=A0 What do you=
think?

Regards,
Henson
--000000000000cf9b6a064c8f77af--