Bird
0
0

Which JSONB expression will return true for '{"a":1, "b":2}'::jsonb @> ?

easy📝 Conceptual Q2 of 15
PostgreSQL - JSON and JSONB

Which JSONB expression will return true for '{"a":1, "b":2}'::jsonb @> ?

A'{"a":2}'::jsonb
B'{"b":3}'::jsonb
C'{"a":1}'::jsonb
D'{"c":1}'::jsonb
Step-by-Step Solution
Solution:
  1. Step 1: Check if left JSONB contains right JSONB

    The left JSONB is {"a":1, "b":2}. It contains {"a":1} because key "a" with value 1 exists.
  2. Step 2: Verify other options

    The other options have either wrong values or keys not present in the left JSONB.
  3. Final Answer:

    Only {"a":1} is contained in the left JSONB -> Option C
  4. Quick Check:

    Containment matches exact key-value pairs = C [OK]
Quick Trick: Values must match exactly for containment [OK]
Common Mistakes:
  • Assuming key presence is enough without matching value
  • Confusing containment direction
  • Ignoring value differences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes