% CREATE EXTENSION first_last_agg; CREATE EXTENSION % SELECT last(x order by y) FROM (VALUES (1, 3), (2, 1), (3, 2)) AS v(x, y); last ------ 1 % SELECT first(x order by y) FROM (VALUES (1, 3), (2, 1), (3, 2)) AS v(x, y); first ------- 2
This library contains two simple aggregate functions,
last, operating on any element type. They return the first or the
last value of the aggregated group, respectively.
It is useful with aggregates with
order by, for easily taking one
element from an aggregate group when you don't really care which do
you get and for emulating a similar functionality from Oracle.