Skip to content

Commit c301c2e

Browse files
committed
WITH TIES: number of rows is optional and defaults to one
FETCH FIRST .. ONLY implements this correctly, but we missed to include it for FETCH FIRST .. WITH TIES in commit 357889e. Author: Vik Fearing Discussion: https://postgr.es/m/[email protected]
1 parent 7966b79 commit c301c2e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/backend/parser/gram.y

+8
Original file line numberDiff line numberDiff line change
@@ -11816,6 +11816,14 @@ limit_clause:
1181611816
n->limitOption = LIMIT_OPTION_COUNT;
1181711817
$$ = n;
1181811818
}
11819+
| FETCH first_or_next row_or_rows WITH TIES
11820+
{
11821+
SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
11822+
n->limitOffset = NULL;
11823+
n->limitCount = makeIntConst(1, -1);
11824+
n->limitOption = LIMIT_OPTION_WITH_TIES;
11825+
$$ = n;
11826+
}
1181911827
;
1182011828

1182111829
offset_clause:

src/test/regress/expected/limit.out

+17
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,23 @@ SELECT thousand
576576
0
577577
(10 rows)
578578

579+
SELECT thousand
580+
FROM onek WHERE thousand < 5
581+
ORDER BY thousand FETCH FIRST ROWS WITH TIES;
582+
thousand
583+
----------
584+
0
585+
0
586+
0
587+
0
588+
0
589+
0
590+
0
591+
0
592+
0
593+
0
594+
(10 rows)
595+
579596
SELECT thousand
580597
FROM onek WHERE thousand < 5
581598
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;

src/test/regress/sql/limit.sql

+5
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,18 @@ SELECT thousand
161161
FROM onek WHERE thousand < 5
162162
ORDER BY thousand FETCH FIRST 2 ROW WITH TIES;
163163

164+
SELECT thousand
165+
FROM onek WHERE thousand < 5
166+
ORDER BY thousand FETCH FIRST ROWS WITH TIES;
167+
164168
SELECT thousand
165169
FROM onek WHERE thousand < 5
166170
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;
167171

168172
SELECT thousand
169173
FROM onek WHERE thousand < 5
170174
ORDER BY thousand FETCH FIRST 2 ROW ONLY;
175+
171176
-- should fail
172177
SELECT ''::text AS two, unique1, unique2, stringu1
173178
FROM onek WHERE unique1 > 50

0 commit comments

Comments
 (0)