mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
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
This commit is contained in:
@@ -647,7 +647,7 @@ View definition:
|
||||
WHERE thousand < 995
|
||||
ORDER BY thousand
|
||||
OFFSET 10
|
||||
FETCH FIRST 5 ROWS WITH TIES;
|
||||
FETCH FIRST (5) ROWS WITH TIES;
|
||||
|
||||
CREATE VIEW limit_thousand_v_2 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand OFFSET 10 FETCH FIRST 5 ROWS ONLY;
|
||||
@@ -679,15 +679,29 @@ View definition:
|
||||
FROM onek
|
||||
WHERE thousand < 995
|
||||
ORDER BY thousand
|
||||
FETCH FIRST (NULL::integer + 1) ROWS WITH TIES;
|
||||
FETCH FIRST ((NULL::integer + 1)) ROWS WITH TIES;
|
||||
|
||||
CREATE VIEW limit_thousand_v_4 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand FETCH FIRST NULL ROWS ONLY;
|
||||
ORDER BY thousand FETCH FIRST (5::bigint) ROWS WITH TIES;
|
||||
\d+ limit_thousand_v_4
|
||||
View "public.limit_thousand_v_4"
|
||||
Column | Type | Collation | Nullable | Default | Storage | Description
|
||||
----------+---------+-----------+----------+---------+---------+-------------
|
||||
thousand | integer | | | | plain |
|
||||
View definition:
|
||||
SELECT thousand
|
||||
FROM onek
|
||||
WHERE thousand < 995
|
||||
ORDER BY thousand
|
||||
FETCH FIRST (5::bigint) ROWS WITH TIES;
|
||||
|
||||
CREATE VIEW limit_thousand_v_5 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand FETCH FIRST NULL ROWS ONLY;
|
||||
\d+ limit_thousand_v_5
|
||||
View "public.limit_thousand_v_5"
|
||||
Column | Type | Collation | Nullable | Default | Storage | Description
|
||||
----------+---------+-----------+----------+---------+---------+-------------
|
||||
thousand | integer | | | | plain |
|
||||
View definition:
|
||||
SELECT thousand
|
||||
FROM onek
|
||||
|
||||
@@ -196,6 +196,9 @@ CREATE VIEW limit_thousand_v_3 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand FETCH FIRST (NULL+1) ROWS WITH TIES;
|
||||
\d+ limit_thousand_v_3
|
||||
CREATE VIEW limit_thousand_v_4 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand FETCH FIRST NULL ROWS ONLY;
|
||||
ORDER BY thousand FETCH FIRST (5::bigint) ROWS WITH TIES;
|
||||
\d+ limit_thousand_v_4
|
||||
CREATE VIEW limit_thousand_v_5 AS SELECT thousand FROM onek WHERE thousand < 995
|
||||
ORDER BY thousand FETCH FIRST NULL ROWS ONLY;
|
||||
\d+ limit_thousand_v_5
|
||||
-- leave these views
|
||||
|
||||
Reference in New Issue
Block a user