Proposal: array_unique_agg() function

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Proposal: array_unique_agg() function
Date: 2022-03-01 13:39:34
Message-ID: CAJ7c6TP8Os9GzjuDkeJZGbF=jjxm6urg7stvRjtLk8q+Gk84NQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I needed an aggregate function similar to array_agg() but which
aggregates only unique values. As it turned out there is no convenient
way of doing this. What I ended up doing instead was aggregating to
JSONB keys and then converting a JSONB object to an array:

SELECT array(select jsonb_object_keys(jsonb_object_agg(mycolumn, true)))
FROM ...

This works but doesn't seem to be the greatest user experience. I
would like to submit a patch that adds array_unique_agg() function
unless anyone has strong objections to this feature.

--
Best regards,
Aleksander Alekseev

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2022-03-01 13:46:53 Re: Proposal: array_unique_agg() function
Previous Message Stephen Frost 2022-03-01 13:35:27 Re: [PATCH] Expose port->authn_id to extensions and triggers