Thread: array exclusion constraint

array exclusion constraint

From
Philip Taylor
Date:
CREATE TABLE foo (
   x CHAR(32) PRIMARY KEY,
   y CHAR(32) NOT NULL,
   EXCLUDE USING gist ((ARRAY[x, y]) WITH &&)
);

ERROR:  data type character[] has no default operator class for access method "gist"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.

Neither gist nor gin work. You can do that with integers using the intarray extension module.
Could you please suggest me a clean way to achieve the same result (using the char data type, not integers)?
Probably I could create a specific operator class or some other workaround, but the intarray implementation looks a bit complex.
Someone so kind to point me in the right direction?

Of course the following produces the same error:

CREATE TABLE bar (
   x VARCHAR[] NOT NULL,
   EXCLUDE USING gist (x WITH &&)
);

Re: array exclusion constraint

From
Robert Haas
Date:
On Sat, Nov 17, 2012 at 1:05 PM, Philip Taylor <philiptaylor51@yahoo.com> wrote:
> CREATE TABLE foo (
>    x CHAR(32) PRIMARY KEY,
>    y CHAR(32) NOT NULL,
>    EXCLUDE USING gist ((ARRAY[x, y]) WITH &&)
> );

My first thought was you were going to have better luck with text
rather than char(n), but a little bit of experimentation suggests to
me that that doesn't work either.  It seems that GIN doesn't support
exclusion constraints and there's no gist opclass for text[],
varchar[], or anyarray.  Bummer.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company