Bird
0
0

Given the table users with a JSONB column preferences and a GIN index on it, what will this query return?

medium📝 query result Q4 of 15
PostgreSQL - Indexing Strategies
Given the table users with a JSONB column preferences and a GIN index on it, what will this query return?
SELECT * FROM users WHERE preferences @> '{"theme": "dark"}';
AAll rows where preferences JSONB contains key "theme" with value "dark"
BAll rows where preferences JSONB contains key "dark"
CAll rows where preferences JSONB equals exactly '{"theme": "dark"}'
DNo rows, because @> operator is invalid for JSONB
Step-by-Step Solution
Solution:
  1. Step 1: Understand @> operator on JSONB

    The @> operator checks if the left JSONB contains the right JSONB as a subset.
  2. Step 2: Interpret the query condition

    The query finds rows where preferences contain the key "theme" with value "dark" anywhere inside.
  3. Final Answer:

    All rows where preferences JSONB contains key "theme" with value "dark" -> Option A
  4. Quick Check:

    @> operator means contains = All rows where preferences JSONB contains key "theme" with value "dark" [OK]
Quick Trick: Use @> to check JSONB containment [OK]
Common Mistakes:
  • Thinking @> checks exact equality
  • Confusing key and value positions
  • Believing @> is invalid for JSONB

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes