Commit c301c2e7 authored by Alvaro Herrera's avatar Alvaro Herrera

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

Author: Vik Fearing
Discussion: https://postgr.es/m/6aa690ef-551d-e24f-2690-c38c2442947c@postgresfriends.org
parent 7966b798
...@@ -11816,6 +11816,14 @@ limit_clause: ...@@ -11816,6 +11816,14 @@ limit_clause:
n->limitOption = LIMIT_OPTION_COUNT; n->limitOption = LIMIT_OPTION_COUNT;
$$ = n; $$ = 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: offset_clause:
......
...@@ -576,6 +576,23 @@ SELECT thousand ...@@ -576,6 +576,23 @@ SELECT thousand
0 0
(10 rows) (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 SELECT thousand
FROM onek WHERE thousand < 5 FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES; ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;
......
...@@ -161,6 +161,10 @@ SELECT thousand ...@@ -161,6 +161,10 @@ SELECT thousand
FROM onek WHERE thousand < 5 FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 2 ROW WITH TIES; 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 SELECT thousand
FROM onek WHERE thousand < 5 FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 1 ROW WITH TIES; ORDER BY thousand FETCH FIRST 1 ROW WITH TIES;
...@@ -168,6 +172,7 @@ SELECT thousand ...@@ -168,6 +172,7 @@ SELECT thousand
SELECT thousand SELECT thousand
FROM onek WHERE thousand < 5 FROM onek WHERE thousand < 5
ORDER BY thousand FETCH FIRST 2 ROW ONLY; ORDER BY thousand FETCH FIRST 2 ROW ONLY;
-- should fail -- should fail
SELECT ''::text AS two, unique1, unique2, stringu1 SELECT ''::text AS two, unique1, unique2, stringu1
FROM onek WHERE unique1 > 50 FROM onek WHERE unique1 > 50
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment