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 <email@example.com> Reviewed-by: Álvaro Herrera <firstname.lastname@example.org> Reviewed-by: Tomas Vondra <email@example.com> Discussion: https://postgr.es/m/CALAY4q9ky7rD_A4vf=FVQvCGngm3LOes-ky0J6euMrg=_Sefirstname.lastname@example.org Discussion: https://email@example.com
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.