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?✗ Incorrect
The
-> operator returns the extracted field as JSON, preserving its JSON format.Which operator would you use to get a JSON field value as plain text in PostgreSQL?
✗ Incorrect
The
->> operator extracts the JSON field and returns it as text.If
data is a JSON column with {"age": 25}, what does data->>'age' return?✗ Incorrect
The
->> operator returns the value as text without quotes, so it returns the string '25'.Can you use the arrow operators to access elements inside a JSON array by index?
✗ Incorrect
You can use
-> or ->> with an integer index to access JSON array elements.What will
data->'missing_key' return if the key does not exist in the JSON object?✗ Incorrect
If the key is missing, the operator returns NULL.
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.