Bird
0
0

Given the table users with a JSON column profile, what does this query return?

medium📝 query result Q13 of 15
PostgreSQL - JSON and JSONB
Given the table users with a JSON column profile, what does this query return?
SELECT profile->>'name' FROM users WHERE profile->>'age' = '30';
AAn error because ->> cannot be used in WHERE.
BAll JSON profiles where age is 30.
CNames of users whose age is 30 as text values.
DAge values of users named '30'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON operators

    The operator ->> extracts JSON object field as text. Here, profile->>'age' gets age as text.
  2. Step 2: Analyze query logic

    The WHERE clause filters rows where age equals '30'. The SELECT returns the name field as text for those rows.
  3. Final Answer:

    Names of users whose age is 30 as text values. -> Option C
  4. Quick Check:

    ->> extracts text field = names for age 30 [OK]
Quick Trick: ->> extracts text; WHERE filters JSON text fields [OK]
Common Mistakes:
  • Thinking ->> cannot be used in WHERE clause
  • Expecting full JSON objects instead of text
  • Confusing age and name fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes