1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-05 09:19:17 +03:00

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

Author: Vik Fearing
Discussion: https://postgr.es/m/6aa690ef-551d-e24f-2690-c38c2442947c@postgresfriends.org
This commit is contained in:
Alvaro Herrera 2020-05-18 19:28:46 -04:00
parent 7966b79801
commit c301c2e739
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
3 changed files with 30 additions and 0 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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