From: John Lumby <johnlumby@hotmail.com>
To: tgl@sss.pgh.pa.us
Cc: pgsql bugs <pgsql-bugs@postgresql.org>
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
Message-ID: <COL116-W49ABA55B2BABBC2237E19DA3BC0@phx.gbl> (raw)
In-Reply-To: <20915.1323505573@sss.pgh.pa.us>
References: <COL116-W333FEC5259FA21D7EF20F3A3B90@phx.gbl>
<20915.1323505573@sss.pgh.pa.us>
Sorry about that, here is a script to demonstrate using a much simpler 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), then successful query explain and run,
then create index and re-run the explain (now uses index) and query (now fails)
John
############################################### snip
#!/bin/bash
# demonstrate bug :
# LIKE predicate and ERROR: 42P22: could not determine which collation to use for string comparison -
# HINT: Use the COLLATE clause ...132
# WARNING this script will (try to) drop and recreate a database named LIKE_42P22
echo "WARNING 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="C"
export LC_ALL="C"
export LC_LOCALE="C"
psql -d postgres -c "DROP DATABASE IF EXISTS \"LIKE_42P22\"";
LANG="C" LC_LOCALE="C" createdb -T template0 -E UTF8 LIKE_42P22;
psql -d LIKE_42P22 -c "CREATE TABLE entity ( id bigint NOT NULL, discriminator character varying(255) NOT NULL )";
date;declare -i rc=0 id=1 count=0 index remdr;
declare -a ALPHABET=(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);
while [[ $rc -eq 0 ]] && [[ $id -le 10000 ]]; do {
((index=id/500)); ((remdr=id%20));discriminator="${ALPHABET[$index]}EPLOY${remdr}padding";
psql -d LIKE_42P22 -c "INSERT INTO entity values ( $id , '${discriminator}' )" >/dev/null;rc=$?;
[[ $rc -eq 0 ]] && ((count=count+1)); ((id=id+1));
}; done; echo "rc= $rc inserted $count entities $(date)";
psql -d LIKE_42P22 -c "ANALYZE entity";
# display catalog metadata
psql -d LIKE_42P22 -c "select datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn, datconnlimit, datlastsysoid, datfrozenxid, dattablespace from pg_database where datname = 'LIKE_42P22'";
psql -d LIKE_42P22 -c "select N.nspname , C.relname, A.attrelid , A.attname , A.atttypid , T.typname , L.collname from pg_attribute A, pg_type T, pg_class C , pg_namespace N , pg_collation L where C.oid = A.attrelid and T.oid = A.atttypid and A.attcollation = L.oid and C.relnamespace = N.oid and N.nspname = 'public' and C.relname = 'entity' and A.attname = 'discriminator'";
# run the problem query before any index on discriminator - it should work
psql -d LIKE_42P22 -c "EXPLAIN select count(*) from entity as e1 where e1.discriminator LIKE 'DEPLOY%'";
psql -d LIKE_42P22 -c "select Count(*) from entity as e1 where e1.discriminator like 'DEPLOY%'"; # should be 500 matches
# now create index and the bug will strike
psql -d LIKE_42P22 -c "CREATE INDEX entity_discriminator ON entity USING btree (discriminator)";
psql -d LIKE_42P22 -c "ANALYZE entity";
psql -d LIKE_42P22 -c "EXPLAIN select count(*) from entity as e1 where e1.discriminator LIKE 'DEPLOY%'";
psql -d LIKE_42P22 -c "select count(*) from entity as e1 where e1.discriminator LIKE 'DEPLOY%'"; # 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, 10 Dec 2011 03:26:13 -0500
> From: tgl@sss.pgh.pa.us
>
> John Lumby <johnlumby@hotmail.com> writes:
> > psql -d proteusdb -c "select count(*) from entity as e1 where ( e1.association_id IN ( select id from entity as e2 where e2.parent_id=3043508) OR e1.association_id=3043508 ) and e1.discriminator LIKE 'DEPLOY%'";
> > ERROR: could not determine which collation to use for string comparison
> > HINT: Use the COLLATE clause to set the collation explicitly.
>
> FWIW, I tried to replicate this on the basis of the limited information
> you gave, and could not. Can you provide a self-contained test case?
>
> regards, 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
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-bugs@postgresql.org
Cc: johnlumby@hotmail.com, tgl@sss.pgh.pa.us
Subject: Re: LIKE predicate and ERROR: 42P22: could not determine which collation to use for string comparison - HINT: Use the COLLATE clause ...
In-Reply-To: <COL116-W49ABA55B2BABBC2237E19DA3BC0@phx.gbl>
References: <COL116-W333FEC5259FA21D7EF20F3A3B90@phx.gbl> <20915.1323505573@sss.pgh.pa.us> <COL116-W49ABA55B2BABBC2237E19DA3BC0@phx.gbl>
* 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