diff --git a/docs/src/main/sphinx/functions/aggregate.rst b/docs/src/main/sphinx/functions/aggregate.rst index 78a6756e5b87..7811cad1d599 100644 --- a/docs/src/main/sphinx/functions/aggregate.rst +++ b/docs/src/main/sphinx/functions/aggregate.rst @@ -93,9 +93,30 @@ Using a filter you retain all information:: General aggregate functions --------------------------- +.. function:: any_value(x) -> [same as input] + + Returns an arbitrary non-null value ``x``, if one exists. ``x`` can be any + valid expression. This allows you to return values from columns that are not + directly part of the aggregation, inluding expressions using these columns, + in a query. + + For example, the following query returns the customer name from the ``name`` + column, and returns the sum of all total prices as customer spend. The + aggregation however uses the rows grouped by the customer identifier + ``custkey`` a required, since only that column is guaranteed to be unique:: + + SELECT sum(o.totalprice) as spend, + any_value(c.name) + FROM tpch.tiny.orders o + JOIN tpch.tiny.customer c + ON o.custkey = c.custkey + GROUP BY c.custkey; + ORDER BY spend; + .. function:: arbitrary(x) -> [same as input] - Returns an arbitrary non-null value of ``x``, if one exists. + Returns an arbitrary non-null value of ``x``, if one exists. Identical to + :func:`any_value`. .. function:: array_agg(x) -> array<[same as input]> diff --git a/docs/src/main/sphinx/functions/list-by-topic.rst b/docs/src/main/sphinx/functions/list-by-topic.rst index f2b4771b1373..74473c985b66 100644 --- a/docs/src/main/sphinx/functions/list-by-topic.rst +++ b/docs/src/main/sphinx/functions/list-by-topic.rst @@ -7,6 +7,7 @@ Aggregate For more details, see :doc:`aggregate` +* :func:`any_value` * :func:`approx_distinct` * :func:`approx_most_frequent` * :func:`approx_percentile` diff --git a/docs/src/main/sphinx/functions/list.rst b/docs/src/main/sphinx/functions/list.rst index 5927cdd25b7b..7a8f0b7bf7e2 100644 --- a/docs/src/main/sphinx/functions/list.rst +++ b/docs/src/main/sphinx/functions/list.rst @@ -31,6 +31,7 @@ A - :ref:`AND ` - :ref:`ANY ` - :func:`any_match` +- :func:`any_value` - :func:`approx_distinct` - :func:`approx_most_frequent` - :func:`approx_percentile`