Bird
0
0

Which of the following is the correct syntax to check if a JSONB column data contains the JSON {"key": "value"}?

easy📝 Syntax Q12 of 15
PostgreSQL - JSON and JSONB

Which of the following is the correct syntax to check if a JSONB column data contains the JSON {"key": "value"}?

SELECT * FROM table WHERE data ___ '{"key": "value"}'::jsonb;
A@>
B<@
C->
D->>
Step-by-Step Solution
Solution:
  1. Step 1: Identify the containment operator

    The @> operator checks if the left JSONB contains the right JSONB.
  2. Step 2: Apply correct syntax

    To check if data contains the JSON, use data @> '{"key": "value"}'::jsonb.
  3. Final Answer:

    @> -> Option A
  4. Quick Check:

    Containment operator = @> [OK]
Quick Trick: Use @> with right side cast to jsonb [OK]
Common Mistakes:
  • Using <@ which reverses containment
  • Using -> or ->> which access keys, not contain
  • Forgetting to cast string to jsonb

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes