order_by
Aliases: orderby (deprecated).
order_by([columnname: col storable, [descending: const bool]?]+) -> ordering
order_by([order_by(...)]+) -> ordering
Specify the ordering when processing data. This is used by ordered windowing functions (like lag and last) as well as ordered aggregation functions (like array_agg).
Ordering is specified by alternating fields and a literal boolean for whether
the field is in ascending (false) or descending (true) order. Because of
backwards compatibility, the function will default to ascending if you omit
specifying a boolean value, however, doing so makes for sometimes ambiguous
expressions, and is not recommended.
Domain
This is a scalar function (calculates a single output value for a single input row).
Categories
Examples
statsby list:array_agg(username, order_by(timestamp, false)), group_by(hostname)
This produces a list of all users for each host, in order of timestamp within each host, from a table with columns timestamp, hostname and username.
statsby list:array_agg(make_object(time:timestamp, host:hostname), order_by(hostname, false, timestamp, true)), group_by(username)
This produces a list of all times and hosts a user has been on, ordered by host alphabetically and reverse chronologically, from a table with columns timestamp, hostname and username.
Updated 8 days ago