Bird
0
0

Given a JSON column settings with value {"theme": {"colors": {"background": "#fff"}}}, which query extracts the background color as JSON, and which extracts it as text?

hard📝 Application Q9 of 15
PostgreSQL - JSON and JSONB
Given a JSON column settings with value {"theme": {"colors": {"background": "#fff"}}}, which query extracts the background color as JSON, and which extracts it as text?
AJSON: settings #> '{theme,colors,background}'; Text: settings #>> '{theme,colors,background}'
BJSON: settings #>> '{theme,colors,background}'; Text: settings #> '{theme,colors,background}'
CJSON: settings -> 'theme' -> 'colors' -> 'background'; Text: settings ->> 'background'
DJSON: settings ->> '{theme,colors,background}'; Text: settings -> '{theme,colors,background}'
Step-by-Step Solution
Solution:
  1. Step 1: Identify JSON extraction operator

    #> extracts JSON value at path array.
  2. Step 2: Identify text extraction operator

    #>> extracts text value at path array.
  3. Step 3: Verify options

    JSON: settings #> '{theme,colors,background}'; Text: settings #>> '{theme,colors,background}' correctly uses #> for JSON and #>> for text extraction with path arrays.
  4. Final Answer:

    JSON: settings #> '{theme,colors,background}'; Text: settings #>> '{theme,colors,background}' -> Option A
  5. Quick Check:

    #> = JSON, #>> = text with path [OK]
Quick Trick: Use #> for JSON, #>> for text with paths [OK]
Common Mistakes:
  • Swapping #> and #>>
  • Using -> and ->> with path arrays
  • Incorrect path syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes