Bird
0
0

What will be the result of this query on a table users with a GIN index on JSONB column profile?

medium📝 query result Q5 of 15
PostgreSQL - JSON and JSONB
What will be the result of this query on a table users with a GIN index on JSONB column profile?
SELECT * FROM users WHERE profile @> '{"age": 30}';
Assuming some rows have "age": 30 inside their JSONB data.
AIt returns all rows where the profile JSONB contains the key "age" with value 30.
BIt returns all rows where the profile JSONB contains the key "age" with any value.
CIt returns no rows because the query syntax is invalid.
DIt returns all rows regardless of the profile content.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the query condition

    The condition profile @> '{"age": 30}' means profile must contain key "age" with value 30.
  2. Step 2: Understand GIN index effect

    The GIN index speeds up this containment check but does not change the result set.
  3. Final Answer:

    It returns all rows where the profile JSONB contains the key "age" with value 30. -> Option A
  4. Quick Check:

    Query returns rows containing specified key-value pair [OK]
Quick Trick: GIN index speeds up @> queries but does not change results [OK]
Common Mistakes:
  • Thinking query returns rows with any "age" value
  • Assuming syntax error in JSONB literal
  • Believing query returns all rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes