0
0
PostgreSQLquery~5 mins

Arrow operators (-> and ->>) in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PostgreSQL arrow operator -> do when used with JSON data?
The -> operator extracts a JSON object field by key and returns it as JSON, preserving the JSON format.
Click to reveal answer
beginner
How is the ->> operator different from -> in PostgreSQL JSON queries?
The ->> operator extracts a JSON object field by key and returns the value as text, not as JSON.
Click to reveal answer
beginner
Given a JSON column data with value {"name": "Alice", "age": 30}, what does data->'name' return?
It returns the JSON string "Alice" including the quotes, because it returns JSON format.
Click to reveal answer
beginner
Given the same JSON column data, what does data->>'name' return?
It returns the text Alice without quotes, because it returns the value as plain text.
Click to reveal answer
intermediate
Can the arrow operators -> and ->> be used to access elements inside JSON arrays in PostgreSQL?
Yes, you can use -> with an integer index to get a JSON element from an array, and ->> to get it as text.
Click to reveal answer
What type of value does the PostgreSQL operator -> return when extracting a JSON field?
AJSON value
BText value
CInteger value
DBoolean value
Which operator would you use to get a JSON field value as plain text in PostgreSQL?
A->>
B@>
C#>
D->
If data is a JSON column with {"age": 25}, what does data->>'age' return?
ANumber 25
B"25"
CText 25
D25
Can you use the arrow operators to access elements inside a JSON array by index?
AOnly with -> but not ->>
BNo, arrow operators only work with object keys
CYes, using an integer index with -> or ->>
DOnly with ->> but not ->
What will data->'missing_key' return if the key does not exist in the JSON object?
AEmpty string
BNULL
CError
DZero
Explain how the PostgreSQL arrow operators -> and ->> differ when extracting data from JSON columns.
Think about the data type returned and how you might use the result.
You got /4 concepts.
    Describe how to access an element inside a JSON array stored in a PostgreSQL column using arrow operators.
    Remember arrays use numbers as keys.
    You got /4 concepts.