0
0
PostgreSQLquery~5 mins

Path extraction with #> and #>> in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the operator #> do in PostgreSQL JSON queries?
The #> operator extracts a JSON object or array at the specified path as JSON data, preserving its JSON type.
Click to reveal answer
beginner
How does #>> differ from #> when extracting JSON data?
#>> extracts the JSON value at the specified path but returns it as text, not as JSON.
Click to reveal answer
beginner
Given a JSON column data with value {"a": {"b": 10}}, what does data #> '{a,b}' return?
It returns the JSON value 10 as JSON type, not as text.
Click to reveal answer
intermediate
What is the input format for the path argument in #> and #>> operators?
The path is given as a text array or a string representing an array of keys/indexes, for example '{key1,key2}'.
Click to reveal answer
intermediate
Why would you use #>> instead of #> when extracting JSON data?
Use #>> when you want the extracted value as plain text for easier comparison or display, instead of JSON format.
Click to reveal answer
What type of value does #> return when extracting JSON data?
AJSON
BText
CInteger
DBoolean
Which operator returns the extracted JSON value as text?
A#>>
B#>
C->
D->>
How do you specify the path for #> operator?
AAs a boolean
BAs a JSON object
CAs a number
DAs a text array or string array like '{key1,key2}'
If you want to extract the value of key 'name' inside a JSON column 'info', which operator returns it as text?
Ainfo #> '{name}'
Binfo #>> '{name}'
Cinfo -> 'name'
Dinfo ->> 'name'
What will data #> '{a,b}' return if data is {"a": {"b": 10}}?
Anull
B10 as text
C10 as JSON
DAn error
Explain how to extract a nested JSON value as JSON and as text using PostgreSQL operators.
Think about the difference between preserving JSON type and converting to text.
You got /3 concepts.
    Describe a scenario where using #>> is more useful than #> for JSON path extraction.
    Consider when you want to use the extracted value in a text context.
    You got /3 concepts.