Re: case insensitive unique index (part 2)

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: lists(at)lists(dot)grot(dot)org
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: case insensitive unique index (part 2)
Date: 2001-05-07 19:54:24
Message-ID: 200105071954.f47JsOC25800@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


I have added the following patch to the FAQ to mention the use of
functional indexes for case-insensitive equality comparisons.

> Hi,
>
> I've trolled the archives and the FAQ and the closest I could come up with was
> the following mailing list message:
>
> http://www.postgresql.org/mhonarc/pgsql-general/2001-01/msg01632.html
>
> which advises that you can do something like this to create a case-insensitive
> unique index:
>
> CREATE UNIQUE INDEX indexname ON tablename (lower(fieldname))
>
> however, that doesn't work under 7.0.2 at least, I get:
>
> mydb=> create unique index forward_rr on forward (lower(name));
> ERROR: DefineIndex: function 'lower(varchar)' does not exist
>
> Futhermore, I want to create the case-insensitive unique index on a tuple of
> varchar fields, ie.:
>
> CREATE UNIQUE INDEX indexname ON tablename (lower(field1), lower(field2), lower(field3))
>
> however, looking at the docs at:
>
> http://www.postgresql.org/users-lounge/docs/7.0/user/sql-createindex.htm
>
> it looks like I will need to instead declare a function f such that it can be used as:
>
> CREATE UNIQUE INDEX indexname ON tablename (f(field1, field2, field3))
>
> and f(n1, n2, n3) returns a unique value for unique combinations of n1, n2 and
> n3...
>
> Since this sounds like something someone must have already done, or should be
> a FAQ, any hints? pointers? functions? PL/SQL code?
>
> Thanks,
> Adi
>
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Attachment Content-Type Size
unknown_filename text/plain 2.8 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ashley Clark 2001-05-07 19:56:31 Re: [GENERAL] Strange notices, should I worry?
Previous Message webb sprague 2001-05-07 19:45:23 Fixed width COPY

Browse pgsql-hackers by date

  From Date Subject
Next Message Mike Mascari 2001-05-07 19:55:52 RE: NOCREATETABLE patch (was: Re: Please, help!(about Postgres))
Previous Message Bruce Momjian 2001-05-07 19:53:25 Re: \c connects as another user instead I want in psql