public inbox for [email protected]
help / color / mirror / Atom feedFrom: Marcos Pegoraro <[email protected]>
To: Shaozhong SHI <[email protected]>
Cc: pgsql-sql <[email protected]>
Subject: Re: How to remove duplicates in an array and maintain the order?
Date: Sat, 8 Jul 2023 12:50:54 -0300
Message-ID: <CAB-JLwY+FKxi-SHM_HQXgYO6uxJu2bb1qgUqjNQyQBgnS9DPhQ@mail.gmail.com> (raw)
In-Reply-To: <CA+i5JwbwFsa2nHM+MG4mXinxx_fEzQGPrpUcz=T8yGDWPQrmnw@mail.gmail.com>
References: <CA+i5JwbwFsa2nHM+MG4mXinxx_fEzQGPrpUcz=T8yGDWPQrmnw@mail.gmail.com>
>
> How to remove duplicated values in an array and maintain the order?
>
> select array_agg(unnest) filter (where row_number = 1) from (select
unnest, ordinality, row_number() over(partition by unnest order by
ordinality) from (select * from
unnest('{7,7,5,6,2,2,3,8,5,4,5}'::integer[]) with ordinality) x order by
ordinality) x
{7,5,6,2,3,8,4}
regards
Marcos
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: How to remove duplicates in an array and maintain the order?
In-Reply-To: <CAB-JLwY+FKxi-SHM_HQXgYO6uxJu2bb1qgUqjNQyQBgnS9DPhQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox