Bird
0
0

The query SELECT * FROM logs WHERE info ?& ARRAY['error', 'timestamp']; returns no rows, but you expect some. What could be the problem?

medium📝 Debug Q7 of 15
PostgreSQL - JSON and JSONB
The query SELECT * FROM logs WHERE info ?& ARRAY['error', 'timestamp']; returns no rows, but you expect some. What could be the problem?
AThe ARRAY syntax is invalid for ?& operator
BThe ?& operator checks if all keys exist; some rows may have only one key
CThe info column is not JSONB type
DThe keys should be comma-separated strings, not an array
Step-by-Step Solution
Solution:
  1. Step 1: Understand the ?& operator

    The ?& operator checks if all keys in the array exist in the JSONB column.
  2. Step 2: Analyze why no rows are returned

    If some rows have only one of the keys, they won't match because all keys must be present.
  3. Final Answer:

    The ?& operator checks if all keys exist; some rows may have only one key -> Option B
  4. Quick Check:

    ?& requires all keys present [OK]
Quick Trick: ?& operator requires all keys to exist [OK]
Common Mistakes:
  • Expecting ?& to check any key instead of all
  • Misusing ARRAY syntax
  • Assuming column type is wrong without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes