]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix deparsing FETCH FIRST <expr> ROWS WITH TIES
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 19 May 2025 15:50:26 +0000 (18:50 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 19 May 2025 15:50:52 +0000 (18:50 +0300)
commit72fe74ca533375fa04264f976d4c4971c6804dce
tree7eecc1553c3bd8ae05fdf190613e9c393b964778
parent9d1a6235960697b5dbc5e0b7d56d59c0a6de3b3d
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
src/backend/utils/adt/ruleutils.c
src/test/regress/expected/limit.out
src/test/regress/sql/limit.sql