pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix deparsing FETCH FIRST <expr> ROWS WITH TIES
Date: Mon, 19 May 2025 15:52:20 +0000
Message-ID: <E1uH2mp-002Pp8-30@gemulon.postgresql.org> (raw)

Fix deparsing FETCH FIRST <expr> ROWS WITH TIES

In the grammar, <expr> is a c_expr, which accepts only a limited set
of integer literals and simple expressions without parens. The
deparsing logic didn't quite match the grammar rule, and failed to use
parens e.g. for "5::bigint".

To fix, always surround the expression with parens. Would be nice to
omit the parens in simple cases, but unfortunately it's non-trivial to
detect such simple cases. Even if the expression is a simple literal
123 in the original query, after parse analysis it becomes a FuncExpr
with COERCE_IMPLICIT_CAST rather than a simple Const.

Reported-by: yonghao lee
Backpatch-through: 13
Discussion: https://www.postgresql.org/message-id/18929-077d6b7093b176e2@postgresql.org

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/54c05292b1ffc8d7ad9305d224225161e4d3d412

Modified Files
--------------
src/backend/utils/adt/ruleutils.c   | 10 ++++++++++
src/test/regress/expected/limit.out | 20 +++++++++++++++++---
src/test/regress/sql/limit.sql      |  5 ++++-
3 files changed, 31 insertions(+), 4 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1uH2mp-002Pp8-30@gemulon.postgresql.org>
Permalink:  ../E1uH2mp-002Pp8-30@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uH2mp-002Pp8-30@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix deparsing FETCH FIRST <expr> ROWS WITH TIES
  In-Reply-To: <E1uH2mp-002Pp8-30@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox