Challenge - 5 Problems
Arrow Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this JSON arrow operator query?
Given the table users with a JSONB column
data containing {"name": "Alice", "age": 30}, what does this query return?SELECT data->'name' FROM users WHERE id = 1;
PostgreSQL
CREATE TABLE users (id INT, data JSONB); INSERT INTO users VALUES (1, '{"name": "Alice", "age": 30}');
Attempts:
2 left
💡 Hint
The -> operator returns a JSON object, including quotes for strings.
✗ Incorrect
The -> operator returns the JSON value as JSON, so strings are quoted. The value is "Alice" including quotes.
❓ query_result
intermediate2:00remaining
What does the ->> operator return in this query?
Using the same
users table, what is the output of:SELECT data->>'age' FROM users WHERE id = 1;
PostgreSQL
CREATE TABLE users (id INT, data JSONB); INSERT INTO users VALUES (1, '{"name": "Alice", "age": 30}');
Attempts:
2 left
💡 Hint
The ->> operator returns text, not JSON.
✗ Incorrect
The ->> operator returns the JSON value as text, so the number 30 is returned as text without quotes.
📝 Syntax
advanced2:30remaining
Which query correctly extracts the city name from this JSONB column?
Given a
locations table with a JSONB column info containing {"address": {"city": "Boston", "zip": "02101"}}, which query returns the city name as text?PostgreSQL
CREATE TABLE locations (id INT, info JSONB); INSERT INTO locations VALUES (1, '{"address": {"city": "Boston", "zip": "02101"}}');
Attempts:
2 left
💡 Hint
Use -> to get JSON object, then ->> to get text value.
✗ Incorrect
Option D first extracts the 'address' JSON object with ->, then extracts 'city' as text with ->>, returning 'Boston' as text.
🧠 Conceptual
advanced1:30remaining
What is the difference between -> and ->> operators in PostgreSQL JSONB?
Choose the correct explanation of the difference between the two operators.
Attempts:
2 left
💡 Hint
Think about the data type each operator returns.
✗ Incorrect
The -> operator returns JSON data including quotes for strings, while ->> returns plain text without JSON formatting.
❓ query_result
expert3:00remaining
What is the output of this nested JSON arrow operator query?
Given a table
What does this query return?
events with JSONB column details containing:{"event": {"name": "Concert", "location": {"city": "NYC", "venue": "Madison Square Garden"}}}What does this query return?
SELECT details->'event'->'location'->>'venue' FROM events WHERE id = 1;
PostgreSQL
CREATE TABLE events (id INT, details JSONB); INSERT INTO events VALUES (1, '{"event": {"name": "Concert", "location": {"city": "NYC", "venue": "Madison Square Garden"}}}');
Attempts:
2 left
💡 Hint
The last operator ->> returns text without quotes.
✗ Incorrect
The query extracts the nested 'venue' value as text, so the output is the string without quotes.