Re: How can unique columns being case-insensitive be accomplished?
От | Ross J. Reedstrom |
---|---|
Тема | Re: How can unique columns being case-insensitive be accomplished? |
Дата | |
Msg-id | 20020916150948.GA797@rice.edu обсуждение исходный текст |
Ответ на | Re: How can unique columns being case-insensitive be accomplished? (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-sql |
On Mon, Sep 16, 2002 at 09:38:46AM -0400, Tom Lane wrote: > "J�rg" <mail2holly@gmx.de> writes: > > How can this problem be overcome? Any ideas? > > Create a unique index on lower(name). I'm sure J�rg can follow this tip, but for the archives, I'll include the full syntax: CREATE UNIQUE INDEX drug_lwr_idx ON drug ( lower(name) ) Another trick would be to use your trigger to lower() the inserted/updated names, rather than only as a test, combined with a regular unique index: CREATE FUNCTION lower_drug () RETURNS OPAQUE AS ' BEGIN NEW.name = lower(NEW.name);RETURN NEW; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER drug_insert BEFORE UPDATE OR INSERT ON drug FOR EACH ROW EXECUTE PROCEDURE lower_drug(); That keeps your data nice and clean and consistent, otherwise the first time a MixedCaseDrugName goes in, it'll keep the correct 'mixedcasedrugname' from being inserted, later. Be very sure that lower() gives you exactly the output you want, however. Ross
В списке pgsql-sql по дате отправления: