Challenge - 5 Problems
JSON Column 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 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;
Attempts:
2 left
💡 Hint
Remember JSON columns store valid JSON objects, not strings with quotes.
✗ Incorrect
The JSON column stores the JSON object as is, without extra quotes. Option A shows the correct JSON object stored.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
One JSON type is binary and supports indexing.
✗ Incorrect
JSONB stores JSON in a binary format, allowing indexing and faster queries compared to JSON which stores text.
📝 Syntax
advanced2: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.Attempts:
2 left
💡 Hint
Check the exact syntax for JSONB column type.
✗ Incorrect
Option B correctly defines a JSONB column. Option B uses JSON type, which is valid but not JSONB. Option B has invalid default syntax for JSONB. Option B uses VARCHAR which is not JSON.
❓ optimization
advanced2: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?Attempts:
2 left
💡 Hint
Think about index types that support JSONB operators.
✗ Incorrect
GIN indexes support fast containment and key-existence queries on JSONB columns. B-tree indexes do not work well for JSONB. Storing JSON as TEXT prevents indexing inside JSON. Queries without indexes are slower.
🔧 Debug
expert3: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?Attempts:
2 left
💡 Hint
Check JSON syntax rules for keys and strings.
✗ Incorrect
JSON requires keys and string values to be double-quoted. The given JSON is invalid because keys are unquoted and string value uses double quotes inside single quotes incorrectly.