0

I want to query jsonb column with the nested field.

select * 
from TABLE_NAME 
where is_active=true 
and extra_info->'leaderboardConfig'->>'tier'= ??? 
order by id desc limit ?"

here extra_info has a lot of other information. while I am interested in leaderboardConfig.tier = "Bronze";

My extra info looks like this

{
    "info":"something",
     "inf2":"something",
    "leaderboardConfig": {
        "profile":123,
        "info1":"something",
        "info2":"something",
        "tier":"Bronze"

    }
}

how do i create index on extra_info->'leaderboardConfig'->>'tier'

2
  • What is your question? Commented Sep 26, 2022 at 12:32
  • how do i create index on extra_info->'leaderboardConfig'->>'tier' Commented Sep 26, 2022 at 13:00

1 Answer 1

2

Just use the exact expression you use in your query when creating the index:

create index on the_table ( (extra_info->'leaderboardConfig'->>'tier') );

Note the extra pair of parentheses which is required because the index is only built on a single expression.

Sign up to request clarification or add additional context in comments.

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.