There are several ways to do case insensitive string matching in SQL. Here are two ways that I've tried and analyzed on a table that doesn't have any indices.
Option 1:
(
LOWER(u.first_name) = LOWER('Lazy') OR
LOWER(u.last_name) = LOWER('Lazy') OR
LOWER(u.first_name || u.last_name) = LOWER('Lazy')
)
Option 2:
(
u.first_name ILIKE 'Lazy' OR
u.last_name ILIKE 'Lazy' OR
u.first_name || u.last_name ILIKE 'Lazy'
)
A potentially third option is to make sure that the parameters sent to the SQL code is cooked, in this case we make the parameter into lower case before sent to the SQL code
Option 1b:
(
LOWER(u.first_name) = 'lazy' OR
LOWER(u.last_name) = 'lazy' OR
LOWER(u.first_name || u.last_name) = 'lazy'
)
Which one do you think is fastest?
Read the whole text (92 more words)