0
0
PostgreSQLquery~20 mins

Arrow operators (-> and ->>) in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arrow Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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}');
A'Alice'
BAlice
C"Alice"
D30
Attempts:
2 left
💡 Hint
The -> operator returns a JSON object, including quotes for strings.
query_result
intermediate
2: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}');
A30
B'30'
C"30"
DNULL
Attempts:
2 left
💡 Hint
The ->> operator returns text, not JSON.
📝 Syntax
advanced
2: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"}}');
ASELECT info->>'address'->>'city' FROM locations WHERE id = 1;
BSELECT info->>'address'->'city' FROM locations WHERE id = 1;
CSELECT info->'address'->'city' FROM locations WHERE id = 1;
DSELECT info->'address'->>'city' FROM locations WHERE id = 1;
Attempts:
2 left
💡 Hint
Use -> to get JSON object, then ->> to get text value.
🧠 Conceptual
advanced
1:30remaining
What is the difference between -> and ->> operators in PostgreSQL JSONB?
Choose the correct explanation of the difference between the two operators.
A-> returns JSON object or array; ->> returns text value without JSON formatting.
B-> returns text value; ->> returns JSON object or array.
CBoth return JSON objects but differ in performance.
D-> returns integer values only; ->> returns string values only.
Attempts:
2 left
💡 Hint
Think about the data type each operator returns.
query_result
expert
3:00remaining
What is the output of this nested JSON arrow operator query?
Given a table 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"}}}');
ANULL
BMadison Square Garden
C'Madison Square Garden'
D"Madison Square Garden"
Attempts:
2 left
💡 Hint
The last operator ->> returns text without quotes.