0
0
PostgreSQLquery~20 mins

Creating JSON columns in PostgreSQL - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Column 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 column insertion?
Consider the table users with a JSON column profile. After running the following insert, what will be the value stored in profile for user_id 1?
PostgreSQL
CREATE TABLE users (user_id SERIAL PRIMARY KEY, profile JSON);
INSERT INTO users (profile) VALUES ('{"name": "Alice", "age": 30}');
SELECT profile FROM users WHERE user_id = 1;
A{"name": "Alice", "age": 30}
B'{"name": "Alice", "age": 30}'
C{name: Alice, age: 30}
DSyntaxError
Attempts:
2 left
💡 Hint
Remember JSON columns store valid JSON objects, not strings with quotes.
🧠 Conceptual
intermediate
1:30remaining
Which data type is best for storing JSON in PostgreSQL?
You want to store JSON data in a PostgreSQL table. Which data type should you use to store JSON that allows indexing and efficient querying?
AJSON
BTEXT
CJSONB
DVARCHAR
Attempts:
2 left
💡 Hint
One JSON type is binary and supports indexing.
📝 Syntax
advanced
2:00remaining
Which CREATE TABLE statement correctly defines a JSONB column?
Select the valid PostgreSQL statement to create a table events with a JSONB column named data.
ACREATE TABLE events (id SERIAL PRIMARY KEY, data VARCHAR);
BCREATE TABLE events (id SERIAL PRIMARY KEY, data JSONB);
CCREATE TABLE events (id SERIAL PRIMARY KEY, data JSONB NOT NULL DEFAULT '{}');
DCREATE TABLE events (id SERIAL PRIMARY KEY, data JSON);
Attempts:
2 left
💡 Hint
Check the exact syntax for JSONB column type.
optimization
advanced
2:30remaining
How to optimize queries on JSONB columns?
You have a JSONB column info in table products. Which approach improves query speed when filtering by a key inside the JSONB?
AStore JSON as TEXT and index it.
BCreate a B-tree index on the JSONB column.
CNo index needed; JSONB queries are always fast.
DCreate a GIN index on the JSONB column.
Attempts:
2 left
💡 Hint
Think about index types that support JSONB operators.
🔧 Debug
expert
3:00remaining
Why does this JSONB insert fail?
You run this insert: INSERT INTO logs (entry) VALUES ('{event: "login", user: 123}'); where entry is JSONB. Why does it fail?
AKeys and string values must be double-quoted in JSON.
BJSONB columns cannot store objects with numbers.
CSingle quotes are not allowed around JSON strings.
DThe table logs does not exist.
Attempts:
2 left
💡 Hint
Check JSON syntax rules for keys and strings.