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 1lxZiU-00065u-FK for pgsql-general@arkaria.postgresql.org; Sun, 27 Jun 2021 18:41:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lxZiT-0004KH-6o for pgsql-general@arkaria.postgresql.org; Sun, 27 Jun 2021 18:41:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxZiS-0004K8-UA for pgsql-general@lists.postgresql.org; Sun, 27 Jun 2021 18:41:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxZiQ-0002X5-PC for pgsql-general@postgresql.org; Sun, 27 Jun 2021 18:41:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 15RIf9oP076948; Sun, 27 Jun 2021 14:41:09 -0400 From: Tom Lane To: "David G. Johnston" cc: Allan Kamau , Postgres General Postgres General Subject: Re: GIN indexed unique constraint? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Sun, 27 Jun 2021 11:28:31 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <76946.1624819269.1@sss.pgh.pa.us> Date: Sun, 27 Jun 2021 14:41:09 -0400 Message-ID: <76947.1624819269@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Sun, Jun 27, 2021 at 11:18 AM Allan Kamau wrote: >> Is it possible to declare a UNIQUE constraint that uses GIN indexing? > Doesn't seem to be possible. The btree_gin extension would provide the > necessary code but it states explicitly that: > "... and they lack one major feature of the standard B-tree code: the > ability to enforce uniqueness." GIN stores all the component elements of its input values separately. It'd be tremendously hard even to identify which inputs share exactly the same component elements; let alone whether inputs sharing the same elements should be considered "equal". For example, ARRAY[1,2] and ARRAY[2,1] would give rise to identical sets of index entries in a GIN array_ops index. In short, no, this isn't something you do with a GIN index. regards, tom lane