Idea: Add first() and last() aggregate functions to the main release
Idea/request for enhancement:
Add the first() and last() aggregate functions to the main release (CREATE
EXTENSION first_last_agg).
Use Case: PostgreSQL equivalent to Oracle's MAX(...) KEEP (DENSE_RANK
FIRST/LAST ORDER BY ...) <https://dba.stackexchange.com/a/324646/100880>
(https://dba.stackexchange.com/a/324646/100880)
GitHub: https://github.com/wulczer/first_last_agg
Reason: As a non-dba, I can’t install additional modules like first_last_agg
.
Thanks,
-Ben
On Sat, 11 Mar 2023 at 23:38, Ben Clements <benhasgonewalking@gmail.com>
wrote:
Idea/request for enhancement:
Add the first() and last() aggregate functions to the main release (CREATE
EXTENSION first_last_agg).Use Case: PostgreSQL equivalent to Oracle's MAX(...) KEEP (DENSE_RANK
FIRST/LAST ORDER BY ...) <https://dba.stackexchange.com/a/324646/100880>
(https://dba.stackexchange.com/a/324646/100880)GitHub: https://github.com/wulczer/first_last_agg
Reason: As a non-dba, I can’t install additional modules like
first_last_agg.
For what it's worth, I support the inclusion of first() and last() in the
main release. It makes queries involving multiple aggregate functions a lot
simpler. Most hosted services only allow official contrib modules.
The module has been around for more than 10 years now. First on
https://www.pgxn.org/dist/first_last_agg, then on
https://github.com/wulczer/first_last_agg. And it's been available from
apt.postgresql.org for a long time now.
Related questions pop up on Stackoverflow every now and then.
(I don't see anything related in the Postgres Todo, yet.)
The implementation in the additional module first_last_agg looks very
simple and straight-forward. Might be an easy task to incorporate into
mainline Postgres. But my C foo is just not good enough to judge whether
the implementation is ideal.
Regards
Erwin