4

I would like to match {[email protected]} with {[email protected], [email protected]}

Doing the case sensitive query is each enough:

select * from users where email @> '{[email protected]}'

However, I cannot find a way to run a case insensitive contains query against an array column.

This page does not instill confidence that this is possible, as there is no mention of case sensitivity. Any thoughts?

0

3 Answers 3

4

A solution that works, but is going to be very slow for larger tables and array is to unnest the array and use ILIKE (or any other case insensitive comparison):

select *
from (
   select id, unnest(email) email_address
   from user
) t
where email_address ILIKE '[email protected]'
Sign up to request clarification or add additional context in comments.

1 Comment

Works great for pagination posts by tags, using LIMIT and OFFSET on the inner select the query execute in little to no time :)
2

I think you can't do it directly, because there are no case insensitive functions for postgresql arrays. The easiest way is to keep both array data and queries in lowercase.

Here is similar problem: Creating case-insensitive indexes on Postgres string array

Comments

0

You can use LOWER/UPPER functions.

select * from users where LOWER("email"::text)::text[] @> '{[email protected]}'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.