Re: Postgres case insensitive searches

From: Lee Hachadoorian <Lee(dot)Hachadoorian+L(at)gmail(dot)com>
To: bhanu udaya <udayabhanu1984(at)hotmail(dot)com>
Cc: Alban Hertroys <haramrae(at)gmail(dot)com>, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, "pgadmin-support(at)postgresql(dot)org" <pgadmin-support(at)postgresql(dot)org>
Subject: Re: Postgres case insensitive searches
Date: 2013-06-29 14:02:55
Message-ID: 51CEE90F.6010009@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support pgsql-general

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 06/29/2013 09:02 AM, bhanu udaya wrote:<br>
<blockquote cite="mid:COL127-W1529DEA2A427BDB5A28C9FD3770(at)phx(dot)gbl"
type="cite">
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr">Hello,<br>
I agree that it is just search condition. But, in a&nbsp;2.5 million
record table search, upper function is not that fast.&nbsp; The
expectation is to get the query retrieved in 100 ms...with all
indexes used.<br>
&nbsp;<br>
I tried with upper, Citext, but the result set was more than a
second.<br>
&nbsp;<br>
The OS server we are using is Linux 64 bit.<br>
&nbsp;<br>
Thanks and Regards<br>
Radha Krishna<br>
&nbsp;<br>
<div>&gt; Subject: Re: [pgadmin-support] [GENERAL] Postgres case
insensitive searches<br>
&gt; From: <a class="moz-txt-link-abbreviated" href="mailto:haramrae(at)gmail(dot)com">haramrae(at)gmail(dot)com</a><br>
&gt; Date: Sat, 29 Jun 2013 09:37:51 +0200<br>
&gt; CC: <a class="moz-txt-link-abbreviated" href="mailto:laurenz(dot)albe(at)wien(dot)gv(dot)at">laurenz(dot)albe(at)wien(dot)gv(dot)at</a>;
<a class="moz-txt-link-abbreviated" href="mailto:pgsql-general(at)postgresql(dot)org">pgsql-general(at)postgresql(dot)org</a>; <a class="moz-txt-link-abbreviated" href="mailto:pgadmin-support(at)postgresql(dot)org">pgadmin-support(at)postgresql(dot)org</a><br>
&gt; To: <a class="moz-txt-link-abbreviated" href="mailto:udayabhanu1984(at)hotmail(dot)com">udayabhanu1984(at)hotmail(dot)com</a><br>
&gt; <br>
&gt; On Jun 29, 2013, at 3:59, bhanu udaya
<a class="moz-txt-link-rfc2396E" href="mailto:udayabhanu1984(at)hotmail(dot)com">&lt;udayabhanu1984(at)hotmail(dot)com&gt;</a> wrote:<br>
&gt; <br>
&gt; &gt; Thanks. But, I do not want to convert into upper and
show the result. <br>
&gt; <br>
&gt; Why not? It won't modify your results, just the search
condition:<br>
&gt; <br>
&gt; SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER
BY val;<br>
&gt; <br>
&gt; Or:<br>
&gt; <br>
&gt; SELECT id, val FROM t WHERE upper(val) LIKE 'AB%' ORDER
BY upper(val), val;<br>
&gt; <br>
&gt; <br>
&gt; &gt; Example, if I have records as below:<br>
&gt; &gt; id type<br>
&gt; &gt; 1. abcd<br>
&gt; &gt; 2. Abcdef<br>
&gt; &gt; 3. ABcdefg<br>
&gt; &gt; 4. aaadf<br>
&gt; &gt; <br>
&gt; &gt; The below query should report all the above <br>
&gt; &gt; <br>
&gt; &gt; select * from table where type like 'ab%'. It should
get all above 3 records. Is there a way the database itself
can be made case-insensitive with UTF8 characterset. I tried
with character type &amp; collation POSIX, but it did not
really help.<br>
&gt; <br>
&gt; I was under the impression this would work, but ISTR that
not every OS has this capability (Postgres makes use of the OS
collation mechanics). So, what OS are you running the server
on?<br>
&gt; <br>
</div>
</div>
</blockquote>
<br>
Duplicate the column with an upper or lowercase version and run all
queries against that.<br>
<br>
CREATE TABLE foo (<br>
&nbsp;&nbsp;&nbsp; id serial PRIMARY KEY,<br>
&nbsp;&nbsp;&nbsp; val text,<br>
&nbsp;&nbsp;&nbsp; val_lower text<br>
);<br>
<br>
Index val_lower. Use triggers to keep val and val_lower in sync and
discard all attempts to write directly to val_lower. Then all
queries would be of the form<br>
<br>
SELECT id, val<br>
FROM foo<br>
WHERE val_lower LIKE 'ab%';<br>
<br>
Wouldn't want to write every table like this, but if (a) query speed
trumps all other requirements and (b) functional index, CITEXT, etc.
have all been rejected as not fast enough&#8230;<br>
<br>
--Lee<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Lee Hachadoorian
Assistant Professor in Geography, Dartmouth College
<a class="moz-txt-link-freetext" href="http://freecity.commons.gc.cuny.edu">http://freecity.commons.gc.cuny.edu</a>
</pre>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 4.5 KB

In response to

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Joshua D. Drake 2013-06-29 16:02:12 Re: Postgres case insensitive searches
Previous Message Alban Hertroys 2013-06-29 13:54:04 Re: [pgadmin-support] Postgres case insensitive searches

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2013-06-29 16:02:12 Re: Postgres case insensitive searches
Previous Message Alban Hertroys 2013-06-29 13:54:04 Re: [pgadmin-support] Postgres case insensitive searches