cockroachdb / cockroachdb/cockroach
sql: support `FETCH .. WITH TIES` clause
Open
C-enhancement
T-sql-queries
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The `WITH TIES` option of `FETCH` can be used to include all rows beyond the limit that tie with the last row in the result set, according to the `ORDER BY` clause (see the [Postgres docs](https://www.postgresql.org/docs/16/sql-select.html#SQL-LIMIT)). Here's an example:
```sql
CREATE TABLE t (k INT PRIMARY KEY, v INT);
-- CREATE TABLE
INSERT INTO t VALUES (1, 100), (2, 20), (3, 100);
-- INSERT 0 3
SELECT * FROM t ORDER BY v FETCH FIRST 2 ROWS WITH TIES;
-- k | v
-- ---+-----
-- 2 | 20
-- 1 | 100
-- 3 | 100
-- (3 rows)
```
Jira issue: CRDB-39183
Contributor guide
Assessment
This issue has not been assessed yet.