Case insensitive query on existing data

Started by Saurav Sarkarover 5 years ago3 messagesgeneral
Jump to latest
#1Saurav Sarkar
saurav.sarkar1@gmail.com

Hi All,

We use PostgreSQL JSONB storage.

One of the keys in the JSON will be always have a "name" key.

We want to perform case insensitive query on the name key.

Our application is already live so we have some data and have existing
indexes on the name key.

I understand that one of the ways is to create index on the lower(name)
and use the lower function. And then to recreate the indexes on the name
key.

Is there any other way through which this can be achieved ? May be an
option to not to recreate indexes.

Thanks and Best Regards,
Saurav

#2Michael Lewis
mlewis@entrata.com
In reply to: Saurav Sarkar (#1)
Re: Case insensitive query on existing data

create index concurrently lower( jsonb->>'name' ), drop old_index
concurrently, ensure that where/on/group by conditions use lower(
jsonb->>'name' ), then take lunch.

What's your concern with this process?

Show quoted text
#3Saurav Sarkar
saurav.sarkar1@gmail.com
In reply to: Michael Lewis (#2)
Re: Case insensitive query on existing data

Thanks a lot Michael . Concurrent index building solves my problem of
building index without locking.

Best Regards,
Saurav

On Thu, Aug 13, 2020 at 10:45 PM Michael Lewis <mlewis@entrata.com> wrote:

Show quoted text

create index concurrently lower( jsonb->>'name' ), drop old_index
concurrently, ensure that where/on/group by conditions use lower(
jsonb->>'name' ), then take lunch.

What's your concern with this process?