You are on page 1of 1

PostgreSQL 13: LIMIT … WITH TIES

September 16, 2020/in 2ndQuadrant, Alvaro's PlanetPostgreSQL, PostgreSQL 13 /by


Álvaro Herrera
One of the new features in PostgreSQL 13 is the SQL-standard WITH TIES clause to
use with LIMIT — or, as the standard calls that, FETCH FIRST n ROWS. Thanks are due
to Surafel Temesgen as initial patch author; Tomas Vondra and yours truly for some
additional code fixes; and reviewers Andrew Gierth and Erik Rijkers. You can peruse
the commit message.

[ T ] Maggie Taylor - A Caucus-Race (Alice in Wonderland) (2007)


A caucus race. An illustration by Maggie Taylor.
Ties are very frequently when ranking things; for instance, in a caucus race you
could have many ties, and for sure you don’t want to deprive participants of their
prizes! What WITH TIES does is pretty simple: it adds any following row or rows to
your result set, if they rank equal to the last row returned per the LIMIT clause,
according to the ORDER BY claus

You might also like