first_last
Aggregate functions to return first or last “n” elements in a group
first_last · Aggregate functions to return first or last “n” elements in a group
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101366 | first_last | first_last | 0.1.1 | FUNC | PostgreSQL | SQL |
Usage
Sources:
- Official upstream README
- Official extension control file (first_last.control)
- Official extension SQL (first_last–0.1.0–0.1.1.sql)
first_last — This extension provides four aggregates: first(anyelement) first(anyelement, int4) last(anyelement) last(anyelement, int4). Use it when SQL needs these specialized functions or aggregates. Use the pinned upstream revision linked above as the API boundary and test it on the target PostgreSQL build.
Core Workflow
Install the extension in the intended database, run the smallest upstream example above when available, and verify the installed version and returned values before integrating it into application SQL.
Important Objects
agg_first(IN p_state anyarray, IN p_new_element anyelement, IN p_limit int4)is an extension function and returnsanyarray.agg_first(IN p_state anyelement, IN p_new_element anyelement)is an extension function and returnsanyelement.agg_last(IN p_state anyarray, IN p_new_element anyelement, IN p_limit int4)is an extension function and returnsanyarray.agg_last(IN p_state anyelement, IN p_new_element anyelement)is an extension function and returnsanyelement.firstis an aggregate exposed by the extension.lastis an aggregate exposed by the extension.
Requirements and Caveats
- The reviewed control file declares default version
0.1.1. - The control file marks the extension as non-relocatable.
- The control file does not require superuser-only installation.
- Confirm privileges, supported PostgreSQL versions, upgrade behavior, and failure cases against the pinned source before production use.