pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedGIN indexed unique constraint?
4+ messages / 3 participants
[nested] [flat]
* GIN indexed unique constraint?
@ 2021-06-27 18:18 Allan Kamau <kamauallan@gmail.com>
2021-06-27 18:28 ` Re: GIN indexed unique constraint? David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Allan Kamau @ 2021-06-27 18:18 UTC (permalink / raw)
To: pgsql-general
Hi,
Is it possible to declare a UNIQUE constraint that uses GIN indexing?
If so, what would the definition look like?
Allan.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: GIN indexed unique constraint?
2021-06-27 18:18 GIN indexed unique constraint? Allan Kamau <kamauallan@gmail.com>
@ 2021-06-27 18:28 ` David G. Johnston <david.g.johnston@gmail.com>
2021-06-27 18:41 ` Re: GIN indexed unique constraint? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: David G. Johnston @ 2021-06-27 18:28 UTC (permalink / raw)
To: Allan Kamau <kamauallan@gmail.com>; +Cc: pgsql-general
On Sun, Jun 27, 2021 at 11:18 AM Allan Kamau <kamauallan@gmail.com> 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."
https://www.postgresql.org/docs/current/btree-gin.html
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: GIN indexed unique constraint?
2021-06-27 18:18 GIN indexed unique constraint? Allan Kamau <kamauallan@gmail.com>
2021-06-27 18:28 ` Re: GIN indexed unique constraint? David G. Johnston <david.g.johnston@gmail.com>
@ 2021-06-27 18:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-06-27 19:39 ` Re: GIN indexed unique constraint? Allan Kamau <kamauallan@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2021-06-27 18:41 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Allan Kamau <kamauallan@gmail.com>; pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sun, Jun 27, 2021 at 11:18 AM Allan Kamau <kamauallan@gmail.com> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: GIN indexed unique constraint?
2021-06-27 18:18 GIN indexed unique constraint? Allan Kamau <kamauallan@gmail.com>
2021-06-27 18:28 ` Re: GIN indexed unique constraint? David G. Johnston <david.g.johnston@gmail.com>
2021-06-27 18:41 ` Re: GIN indexed unique constraint? Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-06-27 19:39 ` Allan Kamau <kamauallan@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Allan Kamau @ 2021-06-27 19:39 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-general
On Sun, Jun 27, 2021 at 9:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Sun, Jun 27, 2021 at 11:18 AM Allan Kamau <kamauallan@gmail.com>
> 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
>
Thank you David and Tom for your speedy and informative responses.
Allan.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-06-27 19:39 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 18:18 GIN indexed unique constraint? Allan Kamau <kamauallan@gmail.com>
2021-06-27 18:28 ` David G. Johnston <david.g.johnston@gmail.com>
2021-06-27 18:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-06-27 19:39 ` Allan Kamau <kamauallan@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox