Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
PostgreSQL - JSON and JSONB
What will be the output of this query?
SELECT jsonb_array_length('[{"a":1},{"b":2}]'::jsonb);
A2
B1
CError: invalid function
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand jsonb_array_length function

    This function returns the number of elements in a JSONB array.
  2. Step 2: Analyze input JSONB array

    The input is an array with two objects: {"a":1} and {"b":2}.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    jsonb_array_length counts array elements correctly [OK]
Quick Trick: Use jsonb_array_length to count JSON array elements [OK]
Common Mistakes:
  • Confusing JSON and JSONB types
  • Expecting error due to complex objects
  • Assuming function counts keys inside objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes