![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm using Postgres and the end-users are complaining that the search features provided by the web app are case-sensitive (via Postgres). Is there a way to do a case-insensitive version of select statements? Not all statements are of the form "=" or "like" but often of the form "...where lastname >= 'smith';" so the I don;t think the '~*' operator will work here for me in all cases. Is there a way to do this type of case-insensitive comparison? Is there a way to designate certain tables or columns be compared on a case-insensitive basis ? Thanks RVince |
#3
| |||
| |||
|
|
Is there a way to designate certain tables or columns be compared on a case-insensitive basis ? Thanks RVince |
#4
| |||
| |||
|
|
There's a case-insensitive string type in contrib (the "Additional Supplied Modules"): |
#5
| |||
| |||
|
|
There's a case-insensitive string type in contrib (the "Additional Supplied Modules"): There are unpleasant surprises with that, like the fact that unique index of that type is not case insensitive. Standard varchar data type, combined with a function index or a trigger should be more than adequate. |
#6
| |||
| |||
|
|
Mladen Gogala wrote: There's a case-insensitive string type in contrib (the "Additional Supplied Modules"): There are unpleasant surprises with that, like the fact that unique index of that type is not case insensitive. Standard varchar data type, combined with a function index or a trigger should be more than adequate. What you say seems to contradict citext's documentation: The citext data type allows you to eliminate calls to lower in SQL queries, and allows a primary key to be case-insensitive. Can you explain? Yours, Laurenz Albe |
#7
| |||
| |||
|
|
There are unpleasant surprises with that, like the fact that unique index of that type is not case insensitive. Standard varchar data type, combined with a function index or a trigger should be more than adequate. What you say seems to contradict citext's documentation: The citext data type allows you to eliminate calls to lower in SQL queries, and allows a primary key to be case-insensitive. Can you explain? You skipped a passage in the documentation: "If you declare a column as UNIQUE or PRIMARY KEY, the implicitly generated index is case-sensitive. So it's useless for case-insensitive searches, and it won't enforce uniqueness case-insensitively. " |
#8
| |||
| |||
|
|
Oh, I see. I think you got confused here, because the sentence you quote is a description of a drawback of the "standard approach" using "WHERE lower(col) = LOWER(?)", *not* a drawback of citext. |
#9
| |||
| |||
|
|
It seems to me that citext is a good replacement for the type text, not for the type varchar(n). |
|
I would still use the standard varchar type for the vast majority of cases and use trigger and/or functional indexes to resolve the case insensitive search. |
|
The trick to make it perform better was to add a column, named something like lower_col1 and populate it by a trigger. That would help the optimizer, at the expense of violating the relational rules and storing the duplicate information. That column could then be indexed normally. This method still provides the best performance, on all databases I know of, with the notable exception of Oracle 11i. |
#10
| |||
| |||
|
|
It seems to me that citext is a good replacement for the type text, not for the type varchar(n). |
|
I would still use the standard varchar type for the vast majority of cases and use trigger and/or functional indexes to resolve the case insensitive search. |
|
The trick to make it perform better was to add a column, named something like lower_col1 and populate it by a trigger. That would help the optimizer, at the expense of violating the relational rules and storing the duplicate information. That column could then be indexed normally. This method still provides the best performance, on all databases I know of, with the notable exception of Oracle 11i. |
![]() |
| Thread Tools | |
| Display Modes | |
| |