Support FETCH FIRST WITH TIES WITH TIES is an option to the FETCH FIRST N ROWS clause (the SQL standard's spelling of LIMIT), where you additionally get rows that compare equal to the last of those N rows by the columns in the mandatory ORDER BY clause. There was a proposal by Andrew Gierth to implement this functionality in a more powerful way that would yield more features, but the other patch had not been finished at this time, so we decided to use this one for now in the spirit of incremental development. Author: Surafel Temesgen <firstname.lastname@example.org> Reviewed-by: Álvaro Herrera <email@example.com> Reviewed-by: Tomas Vondra <firstname.lastname@example.org> Discussion: https://postgr.es/m/CALAY4q9ky7rD_A4vf=FVQvCGngm3LOes-ky0J6euMrg=_Seemail@example.com Discussion: https://firstname.lastname@example.org
Every so often someone needs solution to getting first (or couple of first) values for given column. Or last.
For some cases (when there is not many groups) you can use recursive queries. But it's not always the best choice.
Let's try to implement first() and last() aggregates, so these could be easily used by anybody.