Storing a case insensitive varchar in PostgreSQL Storing a case insensitive varchar in PostgreSQL postgresql postgresql

Storing a case insensitive varchar in PostgreSQL


From the docs

CREATE UNIQUE INDEX lower_title_idx ON films ((lower(title)));


If the tables are not yet populated you may consider simply converting to a standard upper or lower case prior to doing any insertions and making the field a primary key (or just have a unique constraint). If the user want to see his userid in the case he specified this could be another column in the database.

Update:Based on the updated tags I would still suggest the solution I have proposed as being less dependent on a particular DBMS.


Do note that PostgreSQL 8.4 (currently beta) will have a case-insensitive text type.