Skip to content

Support distinct aggregation with ordering over different expressions #20725

Open
@findepi

Description

@findepi

WIth DISTINCT this works

trino> SELECT array_agg(DISTINCT concat(value, value) ) csv_value
    -> FROM (VALUES 'a', 'b', 'c', 'b') t(value);
  csv_value
--------------
 [cc, aa, bb]

with ORDER BY this works

trino> SELECT array_agg( concat(value, value) ORDER BY value) csv_value
    -> FROM (VALUES 'a', 'b', 'c', 'b') t(value);
    csv_value
------------------
 [aa, bb, bb, cc]
(1 row)

with both DISTINCT and ORDER BY there is an error

trino> SELECT array_agg(DISTINCT concat(value, value) ORDER BY value) csv_value
    -> FROM (VALUES 'a', 'b', 'c', 'b') t(value);
Query 20240215_185707_00008_3tuur failed: line 1:57: For aggregate function with DISTINCT, ORDER BY expressions must appear in arguments
SELECT array_agg(DISTINCT concat(value, value) ORDER BY *value*) csv_value ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions