Bird
0
0

What will be the result of this query?

medium📝 query result Q5 of 15
PostgreSQL - JSON and JSONB

What will be the result of this query?
SELECT '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb;

Afalse
Btrue
Cnull
Dsyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the JSONB values

    The left JSONB has keys "a" and "b" with values 1 and 2. The right JSONB has key "b" with value 2.
  2. Step 2: Check containment

    Since the left contains the right's key-value pair, the result is true.
  3. Final Answer:

    The query returns true because left contains right -> Option B
  4. Quick Check:

    Containment returns true if left has right subset = A [OK]
Quick Trick: Containment returns true if all right pairs in left [OK]
Common Mistakes:
  • Confusing containment direction
  • Expecting false if extra keys exist
  • Thinking syntax error due to casting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes