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 357889eb17.

Author: Vik Fearing
Discussion: https://postgr.es/m/6aa690ef-551d-e24f-2690-c38c2442947c@postgresfriends.org
pull/54/head
Alvaro Herrera 5 years ago
parent 7966b79801
commit c301c2e739
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
  1. 8
      src/backend/parser/gram.y
  2. 17
      src/test/regress/expected/limit.out
  3. 5
      src/test/regress/sql/limit.sql

@ -11816,6 +11816,14 @@ limit_clause:
n->limitOption = LIMIT_OPTION_COUNT;
$$ = n;
}
| FETCH first_or_next row_or_rows WITH TIES
{
SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
n->limitOffset = NULL;
n->limitCount = makeIntConst(1, -1);
n->limitOption = LIMIT_OPTION_WITH_TIES;
$$ = n;
}
;
offset_clause:

@ -576,6 +576,23 @@ SELECT thousand
0
(10 rows)
SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST ROWS WITH TIES;
thousand
----------
0
0
0
0
0
0
0
0
0
0
(10 rows)
SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;

@ -161,6 +161,10 @@ SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 2 ROW WITH TIES;
SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST ROWS WITH TIES;
SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;
@ -168,6 +172,7 @@ SELECT thousand
SELECT thousand
FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 2 ROW ONLY;
-- should fail
SELECT ''::text AS two, unique1, unique2, stringu1
FROM onek WHERE unique1 > 50

Loading…
Cancel
Save