Re: search/select case-insensitivly.

From: Andrew McMillan <andrew(at)catalyst(dot)net(dot)nz>
To: Hervé Piedvache <herve(at)elma(dot)fr>
Cc: Zhidian Du <duzhidian(at)hotmail(dot)com>, pgsql-php(at)postgresql(dot)org
Subject: Re: search/select case-insensitivly.
Date: 2002-10-22 10:22:47
Message-ID: 1035282167.6372.153.camel@kant.mcmillan.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Tue, 2002-10-22 at 22:10, Hervé Piedvache wrote:
> The best way is to always save data in your database in the same format ...
> upper or lower ... then create an index on your field classicaly ...
>
> CREATE INDEX ix_name ON mytable(name);
> SELECT name FROM mytable WHERE name = '" . strtolower($Name) ."';
>
> You will ever use the index ... and it's simple to implement ...
> You can also easily do an update of your database like :
> update mytable set name=lower(name);
> to get all the old data in the good format ...
> Do not forget to vacuum the table after that !

Yes, of course you can do that - I was assuming there was a reason why
the poster wanted case preserved.

I generally preserve case for email addresses, for example. Sometimes
the LHS of an e-mail address is case sensitive, even though the RHS
(domain name) may not be. Searching on such a field, however, I would
probably want to search case insensitively.

There are other reasons for preserving case, of course - especially the
case that people write their names. I usually write my own name
McMillan, and it _infuriates_ me when I see software that has translated
that to Mcmillan. Lest you think that is easily computed, I know people
with names which are correctly capitalised as Macindoe and Macinnes -
the capitalisation is idiosyncratic. If you remove the capitalisation
when you write those values to the file you are removing potentially
valuable information.

Finally, you should also consider:

update mytable set name=lower(name) WHERE name != lower(name);

will require a lot less vacuuming :-)

Cheers,
Andrew.
--
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Survey for free with http://survey.net.nz/
---------------------------------------------------------------------

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Bruno Wolff III 2002-10-22 11:46:28 Re: search/select case-insensitivly.
Previous Message Hervé Piedvache 2002-10-22 09:10:47 Re: search/select case-insensitivly.