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 1mKhkS-0002Li-5J for pgsql-general@arkaria.postgresql.org; Mon, 30 Aug 2021 13:54:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mKhkQ-0006AI-V2 for pgsql-general@arkaria.postgresql.org; Mon, 30 Aug 2021 13:54:50 +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 1mKhkQ-0006AA-ML for pgsql-general@lists.postgresql.org; Mon, 30 Aug 2021 13:54:50 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKhkN-0006Yl-RN for pgsql-general@lists.postgresql.org; Mon, 30 Aug 2021 13:54:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Reply-To:Message-ID:Subject:Cc:To:Sender:From:Date: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ofUzReVLUb+Tkah9Cv37kYCkthzdBDTJpXj7GBoUkgM=; b=V90glEPLNuHj5Z1W4UEHMjCVJj jh4YqNdWZkZosVfhMFdnBX9rVZCBPvuZ5Tmzl6+Rwg1somSxgYtlM9xpeg6v0qKt7S1uu5jRtauwI ejXhGhD/COE0a5euV3EBBJ/S62sBiwQPjjKu72JrvhAvQrZWzl6QhHbeTLDViIowIvlo=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mKhkM-0004yB-Nj; Mon, 30 Aug 2021 15:54:46 +0200 Date: Mon, 30 Aug 2021 15:54:46 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: =?utf-8?B?UMOzbCBVYSBMYW/DrW5lY2jDoWlu?= Cc: PostgreSQL General Subject: Re: Arrays - selecting (and not removing) duplicates... Message-ID: <20210830135446.GB14443@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Aug 30, 2021 at 01:47:19PM +0100, Pól Ua Laoínecháin wrote: > I was just wondering if there is some (already written) function out > there that will drop this functionality into my lap? Sure, here: #v+ create function array_dups(ANYARRAY) returns ANYARRAY as $$ select array( select i from unnest($1) i group by i having count(*) > 1 ); $$ language sql; #v- Best regards, depesz