0
0
PostgreSQLquery~20 mins

Why JSON support matters in PostgreSQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Mastery in PostgreSQL
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use JSON data type in PostgreSQL?
Which of the following is the main advantage of using the JSON data type in PostgreSQL compared to storing JSON as plain text?
AIt allows PostgreSQL to validate and query JSON data efficiently using built-in functions and indexes.
BIt automatically compresses JSON data to save disk space without any extra configuration.
CIt converts JSON data into XML format for better compatibility with other systems.
DIt prevents any changes to the JSON data once inserted, making it immutable.
Attempts:
2 left
💡 Hint
Think about how PostgreSQL can work with JSON data beyond just storing it as text.
query_result
intermediate
2:00remaining
Querying JSON data in PostgreSQL
Given a table 'users' with a JSON column 'profile' storing {"age": 30, "city": "Boston"}, what is the output of this query? SELECT profile->>'city' FROM users WHERE profile->>'age' = '30';
PostgreSQL
CREATE TABLE users (id SERIAL PRIMARY KEY, profile JSON);
INSERT INTO users (profile) VALUES ('{"age": 30, "city": "Boston"}');
INSERT INTO users (profile) VALUES ('{"age": 25, "city": "Seattle"}');
ABoston
B30
CSeattle
DNULL
Attempts:
2 left
💡 Hint
The ->> operator extracts the JSON value as text for the given key.
📝 Syntax
advanced
2:00remaining
Correct JSON query syntax in PostgreSQL
Which of the following queries correctly extracts the value of the key 'status' from a JSON column 'data' in table 'orders'?
ASELECT data->'status' FROM orders;
BSELECT data->>status FROM orders;
CSELECT data['status'] FROM orders;
DSELECT data->>'status' FROM orders;
Attempts:
2 left
💡 Hint
Use the operator that returns the JSON value as text for easy reading.
optimization
advanced
2:00remaining
Improving JSON query performance in PostgreSQL
Which method improves query performance when filtering rows based on a JSON key's value in PostgreSQL?
AUse a trigger to copy JSON data into a separate text column and index it.
BStore JSON data as plain text and use LIKE queries.
CCreate a GIN index on the JSON column.
DConvert JSON to XML before storing for faster queries.
Attempts:
2 left
💡 Hint
PostgreSQL supports special indexes for JSON data to speed up queries.
🔧 Debug
expert
2:00remaining
Diagnosing JSON query error in PostgreSQL
A developer runs this query: SELECT data->>'price' FROM products WHERE data->>'price' > 100; But it returns an error. What is the cause?
AThe ->> operator is invalid for JSON columns; should use -> instead.
BComparing JSON text values with > operator causes a type error; need to cast to numeric first.
CThe JSON column 'data' must be cast to text before querying.
DPostgreSQL does not support comparison operators on JSON data.
Attempts:
2 left
💡 Hint
Think about the data type returned by ->> and how comparison operators work.