Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qIADS-0000c0-1Z for pgsql-sql@arkaria.postgresql.org; Sat, 08 Jul 2023 15:51:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qIADO-0007Oh-3t for pgsql-sql@arkaria.postgresql.org; Sat, 08 Jul 2023 15:51:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qIADN-0007OM-MT for pgsql-sql@lists.postgresql.org; Sat, 08 Jul 2023 15:51:17 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qIADK-002vuz-Mr for pgsql-sql@lists.postgresql.org; Sat, 08 Jul 2023 15:51:17 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-991fe70f21bso362779266b.3 for ; Sat, 08 Jul 2023 08:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=f10-com-br.20221208.gappssmtp.com; s=20221208; t=1688831473; x=1691423473; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=B2ecAhxagTJ7K77+79AoCxFX0Yx3ZNSzIitXHghXv68=; b=FdCifihzbBtaEC5mo4Ny+8R52NxtjFTaJ4BE5MLAQJfOTPCxJ2X0AH7Vyfb3WUuQXz obHcPdA9sgzb25r38OjmiIQuvVIBac9xwSEZ6ASPyfvLGZuysvageJfPHdf4wMXTSN0L r/GQe32a1d4qzfmiHqrOyIoHL3Sepmjsqp9aCgBDeZWb57jMNYCak5v3O/MiXqf/EXbL s+2ICA0AsjvtJ2EYZw6IwuNqfi5aAxrzVVSGKkDtsndCKJ29rGJFf7QhNxyogtel3fWn KHmxy1Y6OFEGTpFGkucV9nFOH3kvYEPBKzmSC+F3MpovqCO2ymA9cWiral1nvSDVMShX PZ4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688831473; x=1691423473; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=B2ecAhxagTJ7K77+79AoCxFX0Yx3ZNSzIitXHghXv68=; b=SRQ9rtFZevQVyBvo52TcKtVXEoOn26cp66RbD0fHjXkBgvY5WQdhWahc5OWWupeetZ HLbpPW1QHIZ8hIYWBJ7EEWeV8FjqpieD7gD+NRlKSDpZfeU43iqAWZLMQsRxrJ8LlcJ3 bv30O5Pnlhu2T92G3EcXVKxUSJLF/gQLSSZBXjNPE6YMsCtEg097ee4Vz2WQ+nOpFxT3 UUJUksy+x2W4VC2KXodUlC7YUwKr3B0a9TJXQUe8b5Wgkp9Iv+pyc/OlQSIHic3FFPHe /0czn0GFQb5HAEeEySidJOcupuZzyC6i/rTW2WrGjd8GoiOCC5ICkRwWtOohXhgjkUZ8 TK4w== X-Gm-Message-State: ABy/qLZQAgZv76DtYrE2qkI9CDm3zxKgpu99AOnzrFN2MBilRVF0wRGn niggjaGZ6qvMc6c97Jk1rTPknu8hHzPeYV3ZJtzCcA== X-Google-Smtp-Source: APBJJlH8TLm2aq0995vU+bFg6N8iKqETLaSSYfMPc5d0wtqPUXjk5CCQDVrlCN5/p2EfJpol9Juzf9UJTAVQ1CjNIvg= X-Received: by 2002:a17:906:55c5:b0:991:e12e:9858 with SMTP id z5-20020a17090655c500b00991e12e9858mr6641619ejp.64.1688831473328; Sat, 08 Jul 2023 08:51:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Marcos Pegoraro Date: Sat, 8 Jul 2023 12:50:54 -0300 Message-ID: Subject: Re: How to remove duplicates in an array and maintain the order? To: Shaozhong SHI Cc: pgsql-sql Content-Type: multipart/alternative; boundary="0000000000000dba6305fffbb844" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000dba6305fffbb844 Content-Type: text/plain; charset="UTF-8" > > 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 --0000000000000dba6305fffbb844 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
How to remove duplicated values in an a= rray and maintain the order?

select array_agg(unnest) filter (where row_number =3D 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}'::i= nteger[]) with ordinality) x order by ordinality) x

{7,5,6,2,3,8,4}<= /div>

regards
Marcos=C2=A0
--0000000000000dba6305fffbb844--