Skip to content

max_n_by()

Track the largest values and associated data in a set of values

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.

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.
ColumnTypeDescription
max_n_byMaxNByThe compiled aggregate. Note that the exact type will be MaxByInts, MaxByFloats, or MaxByTimes depending on the input type