Skip to content

min_n_by()

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

Since 1.16.0

Construct an aggregate that keeps track of the smallest values passed through it, as well as some associated data which is passed alongside the value.

The syntax is:

min_n_by(
value BIGINT | DOUBLE PRECISION | TIMESTAMPTZ,
data ANYELEMENT,
capacity BIGINT
) MinNBy
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
min_n_byMinNByThe compiled aggregate. Note that the exact type is MinByInts, MinByFloats, or MinByTimes depending on the input type