Re: Best way to store case-insensitive data?

From: Steve Atkins <steve(at)blighty(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Best way to store case-insensitive data?
Date: 2010-06-10 21:26:25
Message-ID: 59353440-AE87-4FAD-BE31-22538D34033F@blighty.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/10/2010 3:50 PM, Mike Christensen wrote:
> I have a column called "email" that users login with, thus I need to
> be able to lookup email very quickly. The problem is, emails are
> case-insensitive. I want foo(at)bar(dot)com to be able to login with
> FOO(at)Bar(dot)com as well. There's two ways of doing this, that I can see:
>
> 1) Every time I lookup an email in the database, do a case-insensitive
> ilike, or cast both sides with LOWER(). I think both are slow,
> correct?

Use a functional index and they won't be.

create index email_lower_idx on foo (lower(email));

select * from foo where lower(email) = lower('foo(at)bar');

> 2) Every time the user updates or saves their email, store it in
> lowercase, and every time I lookup an email, pass in a lowercase
> email. This is somewhat of a bug farm because one might miss some
> little spot in a piece of code where an email is compared or updated.
>
> Is there any way to tell postgres to always store data in lowercase
> form, or just have a flat out case-insensitive column? Thanks!
>
> Mike
>

Cheers,
Steve

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2010-06-10 21:28:38 Re: database response slows while pg_dump is running (8.4.2)
Previous Message Greg Smith 2010-06-10 21:23:58 Re: database response slows while pg_dump is running (8.4.2)