0
0
PostgreSQLquery~20 mins

Path extraction with #> and #>> in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Path Extraction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Extracting a JSON object using #>
Given the table data with a JSONB column info containing:
{"user": {"name": "Alice", "age": 30}}

What is the output of this query?
SELECT info #> '{user}' AS result FROM data;
PostgreSQL
CREATE TABLE data (info JSONB);
INSERT INTO data VALUES ('{"user": {"name": "Alice", "age": 30}}');
A{"user": {"name": "Alice", "age": 30}}
B{"name": "Alice", "age": 30}
CNULL
D"{\"name\": \"Alice\", \"age\": 30}"
Attempts:
2 left
💡 Hint
The operator #> extracts a JSON object at the specified path as JSON, not as text.
query_result
intermediate
2:00remaining
Extracting text from JSON using #>>
Given the same table data with JSONB column info containing:
{"user": {"name": "Alice", "age": 30}}

What is the output of this query?
SELECT info #>> '{user,name}' AS result FROM data;
PostgreSQL
CREATE TABLE data (info JSONB);
INSERT INTO data VALUES ('{"user": {"name": "Alice", "age": 30}}');
AAlice
B"Alice"
C{Alice}
DNULL
Attempts:
2 left
💡 Hint
The #>> operator extracts the value as text, without quotes.
🧠 Conceptual
advanced
2:00remaining
Difference between #> and #>> operators
Which statement correctly describes the difference between the PostgreSQL JSONB operators #> and #>>?
ABoth #> and #>> return JSON objects, but #>> includes metadata.
B#> returns the value as text, while #>> returns a JSON object or array.
C#> returns a JSON object or array at the specified path, while #>> returns the value as text.
D#> extracts only scalar values, #>> extracts nested JSON objects.
Attempts:
2 left
💡 Hint
Think about the data type each operator returns.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in JSON path extraction
Which of the following queries will cause a syntax error in PostgreSQL when extracting a JSON path?
ASELECT info #> 'user,age' FROM data;
BSELECT info #> '{user,age}' FROM data;
CSELECT info #>> '{user,age}' FROM data;
DSELECT info #>> '{user,age}' AS age FROM data;
Attempts:
2 left
💡 Hint
Check the format of the path argument for #> and #>> operators.
optimization
expert
3:00remaining
Optimizing JSON path extraction in large datasets
You have a large table with a JSONB column data. You frequently query nested keys using #> and #>> operators. Which approach will improve query performance the most?
ACreate a GIN index on the JSONB column and use the #> operator in queries.
BCreate a B-tree index on the JSONB column and use the #>> operator in queries.
CCreate no index and rely on sequential scans with #> operator.
DCreate a GIN index on the JSONB column and extract values using #>> operator.
Attempts:
2 left
💡 Hint
Consider which index type supports JSONB path queries and text extraction efficiently.