Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding min_n and max_n aggregates #590

Merged
merged 1 commit into from
Oct 29, 2022
Merged

Adding min_n and max_n aggregates #590

merged 1 commit into from
Oct 29, 2022

Commits on Oct 29, 2022

  1. Adding min_n and max_n aggregates

    This adds new aggregates min_n and max_n for getting the n largest or smallest
    values from a column. It will work with integer, float, and timestamptz values.
    These functions will return an aggregate object which can be combined with
    other such objects via rollup. The data can be extracted from the aggregate
    via into_array or into_values methods, which return either an array of the
    values, or a table containing them.
    
    It further adds min_n_by and max_n_by functions that take one of the above
    types plus an associated piece of data (takes this as an AnyElement, so can be
    any type). This will behave the same as the min_n/max_n above, but will also
    return the associated data for the smallest or largest elements. into_array is
    not implemented for these aggregates, as it's not clear what that array would
    look like, and into_values will require a value of the appropriate type as an
    input to allow postgres to determine the function output (suggested approach is
    to just cast a NULL to the type of the associated data).
    Brian Rowe committed Oct 29, 2022
    Configuration menu
    Copy the full SHA
    9fe5b8f View commit details
    Browse the repository at this point in the history