Bird
0
0

Identify the error in this query that tries to find rows where info JSONB column contains {"active": true}:

medium📝 Debug Q14 of 15
PostgreSQL - JSON and JSONB

Identify the error in this query that tries to find rows where info JSONB column contains {"active": true}:

SELECT * FROM users WHERE info @> '{active: true}';
AWrong operator used, should be <@
BJSON keys must be in double quotes
CMissing cast to jsonb for the right side
DBoolean true must be in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON syntax correctness

    JSON keys must be enclosed in double quotes, so active should be "active".
  2. Step 2: Verify casting and operator

    The query is missing ::jsonb cast, but the main syntax error is the missing quotes around the key.
  3. Final Answer:

    JSON keys must be in double quotes -> Option B
  4. Quick Check:

    JSON keys need double quotes [OK]
Quick Trick: Always quote JSON keys and cast string to jsonb [OK]
Common Mistakes:
  • Forgetting double quotes around keys
  • Not casting string to jsonb
  • Using wrong containment operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes