Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3boX-0007WT-QD for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 07:59:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3boV-0007h6-N2 for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 07:59:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3boV-0007gy-67 for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 07:59:19 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i3boR-0005bB-Sy for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 07:59:18 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id x7U7x6gB025578 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 30 Aug 2019 10:59:11 +0300 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x7U7x5m1020898 for ; Fri, 30 Aug 2019 10:59:06 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: Exclusion constraints on overlapping text arrays? To: pgsql-general@lists.postgresql.org References: From: Achilleas Mantzios Message-ID: Date: Fri, 30 Aug 2019 10:59:05 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------6D52CD30058D7FF7B2E162C9" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.100.3 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-22.6 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,DYN_SPAM_MED6,DYN_SPAM_MED7,DYN_SPAM_SUBJ, HTML_MESSAGE,TW_VF,TW_XV autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------6D52CD30058D7FF7B2E162C9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 30/8/19 10:20 π.μ., Achilleas Mantzios wrote: > On 30/8/19 3:42 π.μ., Ken Tanzer wrote: >> Hi.  Using 9.6.14, I was setting up a table with this: >> >> EXCLUDE using gist (EXCLUDE using gist (grant_number_codes with &&) >> >> Where grant_numbers is a varchar[].  I get this error: >> >> ERROR:  data type character varying[] 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. >> >> I did some Googling, and it looks like you could do this for integer arrays with the intarray extension.  I didn't see anything I'd recognize as an equivalent for varchar (or text) arrays.  Is >> there any way to do this now?  And if not, is there much prospect of this being implemented at some point? >> >> I found a couple of old threads about this.  Not sure if they are still relevant, but listed below. >> >> Also, on a side note, I tried using grant_number_codes::text[] with &&, but that got a syntax error.  Does that mean casting isn't allowed at all in these constraints? > Maybe take a look at https://dba.stackexchange.com/questions/185174/error-data-type-text-has-no-default-operator-class-for-access-method-gist So you download latest version of smlar from here : http://sigaev.ru/git/gitweb.cgi?p=smlar.git following is from commands given to FreeBSD but you get the point % tar xvfz smlar-92dc9c7.tar.gz cd smlar-92dc9c7 gmake (or make in linux) if it complaints about not finding /contrib/contrib-global.mk then you do setenv USE_PGXS 1 (export USE_PGXS=1 in linux) and repeat the make step sudo make install (again solve problems as above) when installed successfully then : psql create extension smlar; --and then create your exclude constraint : alter table your_table_name ADD constraint constrname EXCLUDE USING gist (grant_number_codes _text_sml_ops with &&); >> >> Thanks in advance, >> Ken >> >> 1) This 2014 thread asked about this: >> >> _*array exclusion constraints*_ >> https://www.postgresql.org/message-id/flat/20141113183843.E8AC620362%40smtp.hushmail.com >> >> and pointed toward this 2013 discussion: >> >> _*Todo item: Support amgettuple() in GIN*_ >> https://www.postgresql.org/message-id/flat/5297DC17.7000608%40proxel.se >> >> >> >> -- >> AGENCY Software >> A Free Software data system >> By and for non-profits >> /http://agency-software.org// >> /https://demo.agency-software.org/client/ >> ken.tanzer@agency-software.org >> (253) 245-3801 >> >> Subscribe to the mailing list  to >> learn more about AGENCY or >> follow the discussion. > > > -- > Achilleas Mantzios > IT DEV Lead > IT DEPT > Dynacom Tankers Mgmt -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------6D52CD30058D7FF7B2E162C9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 30/8/19 10:20 π.μ., Achilleas Mantzios wrote:
On 30/8/19 3:42 π.μ., Ken Tanzer wrote:
Hi.  Using 9.6.14, I was setting up a table with this:

EXCLUDE using gist (EXCLUDE using gist (grant_number_codes with &&)

Where grant_numbers is a varchar[].  I get this error:

ERROR:  data type character varying[] 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.


I did some Googling, and it looks like you could do this for integer arrays with the intarray extension.  I didn't see anything I'd recognize as an equivalent for varchar (or text) arrays.  Is there any way to do this now?  And if not, is there much prospect of this being implemented at some point?

I found a couple of old threads about this.  Not sure if they are still relevant, but listed below.

Also, on a side note, I tried using grant_number_codes::text[] with &&, but that got a syntax error.  Does that mean casting isn't allowed at all in these constraints?
Maybe take a look at https://dba.stackexchange.com/questions/185174/error-data-type-text-has-no-default-operator-class-for-access-method-gist

So you download latest version of smlar from here : http://sigaev.ru/git/gitweb.cgi?p=smlar.git
following is from commands given to FreeBSD but you get the point

% tar xvfz smlar-92dc9c7.tar.gz
cd smlar-92dc9c7
gmake (or make in linux)
if it complaints about not finding /contrib/contrib-global.mk then you do
setenv USE_PGXS 1 (export USE_PGXS=1 in linux)
and repeat the make step
sudo make install (again solve problems as above)

when installed successfully then :
psql
create extension smlar;
--and then create your exclude constraint :
alter table your_table_name ADD constraint constrname EXCLUDE USING gist (grant_number_codes _text_sml_ops with &&);


Thanks in advance,
Ken

1) This 2014 thread asked about this:

array exclusion constraints

and pointed toward this 2013 discussion:

Todo item: Support amgettuple() in GIN



--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------6D52CD30058D7FF7B2E162C9--