Skip to main content
Since 1.16.0 Construct an aggregate that keeps track of the largest values passed through it, as well as some associated data which is passed alongside the value.

Arguments

The syntax is:
max_n_by(
    value BIGINT | DOUBLE PRECISION | TIMESTAMPTZ,
    data ANYELEMENT,
    capacity BIGINT
) MaxNBy
NameTypeDefaultRequiredDescription
valueBIGINT | DOUBLE PRECISION | TIMESTAMPTZ-The values passed into the aggregate
dataANYELEMENT-The data associated with a particular value
capacityBIGINT-The number of values to retain.

Returns

ColumnTypeDescription
max_n_byMaxNByThe compiled aggregate. Note that the exact type will be MaxByInts, MaxByFloats, or MaxByTimes depending on the input type