From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: index unique
Date: Tue, 8 Jun 2021 22:50:48 +0200
Message-ID: <99cf7fa9-9788-c576-cb49-3aec780168f6@gmx.net> (raw)
In-Reply-To: <CADX_1aYbmMHK4wqHd=p_fGsNMOgEB7oe0BY_9ZTWv3e-TQx+oA@mail.gmail.com>
References: <CADX_1aYbmMHK4wqHd=p_fGsNMOgEB7oe0BY_9ZTWv3e-TQx+oA@mail.gmail.com>
Marc Millas schrieb am 03.06.2021 um 22:51:
> on a table we need a primary key and to get a unique combinaison, we need 3 columns of that table:
> 1 of type integer,
> 1 of type text,
> 1 of type geometry
>
> creating the PK constraint doesn work: (even with our current small data set)
> ERROR: index row size 6072 exceeds btree version 4 maximum 2704 for index "xxx_spkey"
> DETAIL: Index row references tuple (32,1) in relation "xxx".
> HINT: Values larger than 1/3 of a buffer page cannot be indexed.
> Consider a function index of an MD5 hash of the value, or use full text indexing.
>
> ok. we can do this.
> but if so, we need to create a gist index on the geometry column to do any topology request.
> so 2 indexes containing this single column.
>
> if we install extension btree_gist, no pb to create an index on all 3 columns.
> but as gist does not support unicity, this index cannot be used for the PK.
>
> OK, we may try to use a function to get the bounding box around the geometry objects and use the result into a btree index........
>
> Any idea (I mean: another idea !) to tackle this ?
> Or any critic on the "solution" ??
How do you define the "uniqueness" of the geometry?
GIST can support "uniqueness" through exclusion constraints.
It's not a primary key, so you can't create foreign keys referencing that table,
but it does ensure uniqueness (In fact the "normal" unique indexes are
essentially a special case of exclusion constraints)
create index on the_table using gist (int_column with =, text_col with =, geometry_col with &&);
Replace the && operator with whatever is appropriate for your use case.
Thomas
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: shammat@gmx.net
Subject: Re: index unique
In-Reply-To: <99cf7fa9-9788-c576-cb49-3aec780168f6@gmx.net>
References: <CADX_1aYbmMHK4wqHd=p_fGsNMOgEB7oe0BY_9ZTWv3e-TQx+oA@mail.gmail.com> <99cf7fa9-9788-c576-cb49-3aec780168f6@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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