Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 7513A7E7FA9 for ; Sun, 11 Dec 2011 20:55:51 -0400 (AST) Received: from col0-omc2-s8.col0.hotmail.com ([65.55.34.82]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RZuBH-0001fl-5E for pgsql-bugs@postgresql.org; Mon, 12 Dec 2011 00:55:50 +0000 Received: from COL116-W49 ([65.55.34.71]) by col0-omc2-s8.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 11 Dec 2011 16:55:33 -0800 Message-ID: X-Originating-IP: [65.92.2.205] From: John Lumby To: CC: pgsql bugs Subject: Re: LIKE predicate and ERROR: 42P22: could not determine which collation to use for string comparison - HINT: Use the COLLATE clause ... Date: Sun, 11 Dec 2011 19:55:32 -0500 Importance: Normal In-Reply-To: <20915.1323505573@sss.pgh.pa.us> References: , <20915.1323505573@sss.pgh.pa.us> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 12 Dec 2011 00:55:33.0061 (UTC) FILETIME=[C0613F50:01CCB868] X-Pg-Spam-Score: -3.4 (---) X-Archive-Number: 201112/74 X-Sequence-Number: 31885 Sorry about that=2C=A0=A0 here is a script to demonstrate using a much simp= ler example. It presumes linux and that there is a bash shell at /bin/bash. You should see table created and loaded (takes a few minutes)=2C=A0=A0 then= successful query explain and run=2C then create index and re-run the explain (now uses index) and query (now fa= ils) John ############################################### snip #!/bin/bash #=A0=A0 demonstrate bug :=20 #=A0=A0 LIKE predicate and ERROR:=A0 42P22: could not determine which colla= tion to use for string comparison - #=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 HINT:=A0 Use the COLLATE clause ...132 #=A0=A0 WARNING=A0=A0 this script will (try to) drop and recreate a databas= e named LIKE_42P22 echo "WARNING=A0=A0 this script will (try to) drop and recreate a database = named LIKE_42P22 press enter to continue or Ctl-C to cancel" read nothing export LANG=3D"C" export LC_ALL=3D"C" export LC_LOCALE=3D"C" psql -d postgres -c "DROP DATABASE IF EXISTS \"LIKE_42P22\""=3B LANG=3D"C" LC_LOCALE=3D"C" createdb -T template0 -E UTF8 LIKE_42P22=3B psql -d LIKE_42P22 -c "CREATE TABLE entity ( id bigint NOT NULL=2C discrimi= nator character varying(255) NOT NULL )"=3B date=3Bdeclare -i rc=3D0 id=3D1 count=3D0 index remdr=3B declare -a ALPHABET=3D(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)= =3B while [[ $rc -eq 0 ]] && [[ $id -le 10000 ]]=3B do { =A0=A0=A0=A0 ((index=3Did/500))=3B ((remdr=3Did%20))=3Bdiscriminator=3D"${A= LPHABET[$index]}EPLOY${remdr}padding"=3B =A0=A0=A0=A0 psql -d LIKE_42P22 -c "INSERT INTO entity values ( $id =2C '${= discriminator}' )" >/dev/null=3Brc=3D$?=3B =A0=A0=A0=A0 [[ $rc -eq 0 ]] && ((count=3Dcount+1))=3B ((id=3Did+1))=3B }=3B done=3B echo "rc=3D $rc inserted $count entities $(date)"=3B psql -d LIKE_42P22 -c "ANALYZE entity"=3B #=A0=A0 display catalog metadata psql -d LIKE_42P22 -c "select datname=2C datdba=2C encoding=2C datcollate= =2C datctype=2C datistemplate=2C datallowconn=2C datconnlimit=2C datlastsys= oid=2C datfrozenxid=2C dattablespace from pg_database where datname =3D 'LI= KE_42P22'"=3B psql -d LIKE_42P22 -c "select N.nspname =2C C.relname=2C A.attrelid =2C A.a= ttname =2C A.atttypid =2C T.typname =2C L.collname from pg_attribute A=2C p= g_type T=2C pg_class C =2C pg_namespace N =2C pg_collation L where C.oid = =3D A.attrelid and T.oid =3D A.atttypid and A.attcollation =3D L.oid and C.= relnamespace =3D N.oid and N.nspname =3D 'public' and C.relname =3D 'entity= ' and A.attname =3D 'discriminator'"=3B #=A0 run the problem query before any index on discriminator=A0 -=A0 it sho= uld work psql -d LIKE_42P22 -c "EXPLAIN select count(*) from entity as e1 where e1.d= iscriminator LIKE 'DEPLOY%'"=3B psql -d LIKE_42P22 -c "select Count(*) from entity as e1 where e1.discrimin= ator like 'DEPLOY%'"=3B # should be 500 matches #=A0=A0 now create index and the bug will strike psql -d LIKE_42P22 -c "CREATE INDEX entity_discriminator ON entity USING bt= ree (discriminator)"=3B psql -d LIKE_42P22 -c "ANALYZE entity"=3B psql -d LIKE_42P22 -c "EXPLAIN select count(*) from entity as e1 where e1.d= iscriminator LIKE 'DEPLOY%'"=3B psql -d LIKE_42P22 -c "select count(*) from entity as e1 where e1.discrimin= ator LIKE 'DEPLOY%'"=3B=A0 #=A0 should fail ############################################### snip ---------------------------------------- > To: johnlumby@hotmail.com > CC: pgsql-bugs@postgresql.org > Subject: Re: [BUGS] LIKE predicate and ERROR: 42P22: could not determine = which collation to use for string comparison - HINT: Use the COLLATE clause= ... > Date: Sat=2C 10 Dec 2011 03:26:13 -0500 > From: tgl@sss.pgh.pa.us > > John Lumby writes: > > psql -d proteusdb -c "select count(*) from entity as e1 where ( e1.ass= ociation_id IN ( select id from entity as e2 where e2.parent_id=3D3043508) = OR e1.association_id=3D3043508 ) and e1.discriminator LIKE 'DEPLOY%'"=3B > > ERROR: could not determine which collation to use for string compariso= n > > HINT: Use the COLLATE clause to set the collation explicitly. > > FWIW=2C I tried to replicate this on the basis of the limited information > you gave=2C and could not. Can you provide a self-contained test case? > > regards=2C tom lane > > -- > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs =