From tlqmail@yahoo.com Mon May 26 02:48:31 2003 X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id BA7B5925921 for ; Sun, 25 May 2003 22:48:31 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 24117-04 for ; Sun, 25 May 2003 22:48:30 -0400 (EDT) Received: from web40204.mail.yahoo.com (web40204.mail.yahoo.com [66.218.78.65]) by developer.postgresql.org (Postfix) with SMTP id 8FC7B925914 for ; Sun, 25 May 2003 22:48:29 -0400 (EDT) Message-ID: <20030526024829.32935.qmail@web40204.mail.yahoo.com> Received: from [66.139.15.154] by web40204.mail.yahoo.com via HTTP; Sun, 25 May 2003 19:48:29 PDT Date: Sun, 25 May 2003 19:48:29 -0700 (PDT) From: Mintoo Lall Subject: Using UPPER and TRIM (INDEX usage) To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1520874341-1053917309=:32785" X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/493 X-Sequence-Number: 13658 --0-1520874341-1053917309=:32785 Content-Type: text/plain; charset=us-ascii Hi Everybody, How do I use "TRIM" and "UPPER" both in the SQL statement and still use the index. I created an index on myTable in the following way CREATE INDEX index_fname_myTable ON myTable USING btree (upper(fname)); Now the SQL I used was SELECT * FROM myTable where upper(trim(fname))= 'JOHN':: character varying The postgresql doesnt use the index on fname in the above case. But if I use only "UPPER" in the SQL statement, the postgresql uses the index. For eg. SELECT * FROM myTable where upper(fname)= 'JOHN':: character varying Any help is appreciated. Regards Mintoo --------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. --0-1520874341-1053917309=:32785 Content-Type: text/html; charset=us-ascii
Hi Everybody,
 
How do I use "TRIM" and "UPPER" both in the SQL statement and still use the index.
 
I created an index on myTable in the following way
 
CREATE INDEX index_fname_myTable ON myTable USING btree (upper(fname));
Now  the SQL I used was
 
SELECT * FROM myTable where upper(trim(fname))= 'JOHN':: character varying
 
The postgresql doesnt use the index on fname in the above case. 
 
But if I use only "UPPER" in the SQL statement, the postgresql uses the index. For eg. SELECT * FROM myTable where upper(fname)= 'JOHN':: character varying
 
Any help is appreciated.
 
Regards
Mintoo
 
 
 
 


Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo. --0-1520874341-1053917309=:32785-- From ch@rodos.fzk.de Tue May 27 08:55:46 2003 X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 02B47925670 for ; Tue, 27 May 2003 04:55:46 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 99601-10 for ; Tue, 27 May 2003 04:55:44 -0400 (EDT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by developer.postgresql.org (Postfix) with SMTP id BFF2592565F for ; Tue, 27 May 2003 04:55:43 -0400 (EDT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Tue May 27 10:57:15 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id KAA27979; Tue, 27 May 2003 10:55:41 +0200 (METDST) Message-ID: <3ED3280C.2090601@rodos.fzk.de> Date: Tue, 27 May 2003 10:55:40 +0200 From: Christoph Haller User-Agent: Mozilla/5.0 (X11; U; HP-UX 9000/780; en-US; rv:1.3) Gecko/20030321 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: tlqmail@yahoo.com Subject: Re: Using UPPER and TRIM (INDEX usage) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/503 X-Sequence-Number: 13668 > > How do I use "TRIM" and "UPPER" both in the SQL statement and still use the index. > > I created an index on myTable in the following way > > CREATE INDEX index_fname_myTable ON myTable USING btree (upper(fname)); > > Now the SQL I used was > > > SELECT * FROM myTable where upper(trim(fname))= 'JOHN':: character varying > > The postgresql doesnt use the index on fname in the above case. > > But if I use only "UPPER" in the SQL statement, the postgresql uses the index. > For eg. SELECT * FROM myTable where upper(fname)= 'JOHN':: character varying And what happens if you re-write it as SELECT * FROM myTable where trim(upper(fname))= 'JOHN':: character varying Alternatively try CREATE FUNCTION uppertrim (character varying) returns character varying as ' select upper(trim($1)); ' LANGUAGE SQL IMMUTABLE ; and then CREATE INDEX index_fname2_myTable ON myTable USING btree (uppertrim(fname)); Regards, Christoph