Re: Case insensitive primary keys

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jeff Schnitzer <jeff(at)infohazard(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Case insensitive primary keys
Date: 2001-03-13 08:15:45
Message-ID: 3AADD732.FF59D59F@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Schnitzer wrote:
>
> Hello! I've got a question:
>
> I'm trying to create a system with a string (varchar) primary key which
> is *not* case sensitive. Is there any way I can create a primary key
> column which automatically takes care of this?

you can try something like:

CREATE UNIQUE INDEX foo_idx ON tbl (lower(foo));

That will prevent entries duplicates that differ only in case.

> I'm coming at this problem from a java app server, so my hands are
> somewhat bound regarding the queries used to insert and search the
> table. There are solutions, but the ideal (for me) would be for the
> database to ignore the case of my key column. Is this possible?

If you can't change LIKE to ILIKE or foo='x' to lower(foo) = lower('x')
you'll have problems with comparisons.

The only other thing(s) I can suggest are:

1. add a rule/trigger to inserts/updates/selects to do the lower() stuff
for you.
2. you _could_ write your own type, but this is last resort really.

- Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message drevil 2001-03-13 09:00:44 Re: Data type for storing images?
Previous Message Richard Huxton 2001-03-13 08:00:30 Re: display temp table structure?