Re: search/select case-insensitivly. - Mailing list pgsql-php

From Andrew McMillan
Subject Re: search/select case-insensitivly.
Date
Msg-id 1035282167.6372.153.camel@kant.mcmillan.net.nz
Whole thread Raw
In response to Re: search/select case-insensitivly.  (Hervé Piedvache <herve@elma.fr>)
List 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/
---------------------------------------------------------------------


pgsql-php by date:

Previous
From: Hervé Piedvache
Date:
Subject: Re: search/select case-insensitivly.
Next
From: Bruno Wolff III
Date:
Subject: Re: search/select case-insensitivly.