0
0
PostgreSQLquery~20 mins

JSON vs JSONB differences in PostgreSQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON vs JSONB Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in Storage Format
Which statement correctly describes the difference in storage format between JSON and JSONB in PostgreSQL?
ABoth JSON and JSONB store data as plain text but differ in indexing.
BJSON stores data in binary format, while JSONB stores data as plain text.
CJSON stores data as plain text, while JSONB stores data in a binary format.
DBoth JSON and JSONB store data in binary format but differ in compression.
Attempts:
2 left
💡 Hint
Think about how the data is saved internally and how that affects performance.
query_result
intermediate
2:00remaining
Query Result Difference on Duplicate Keys
Given a table with a JSON and a JSONB column both containing the value '{"a":1, "a":2}', what will be the result of selecting these columns?
PostgreSQL
SELECT json_col, jsonb_col FROM test_table;
Ajson_col returns '{"a":1, "a":2}', jsonb_col returns '{"a":2}'
Bjson_col returns '{"a":2}', jsonb_col returns '{"a":1, "a":2}'
CBoth json_col and jsonb_col return '{"a":1, "a":2}'
DBoth json_col and jsonb_col return '{"a":2}'
Attempts:
2 left
💡 Hint
Consider how JSONB handles duplicate keys compared to JSON.
optimization
advanced
2:00remaining
Indexing Performance
Which indexing method is supported only by JSONB and not by JSON in PostgreSQL?
AGIN (Generalized Inverted Index)
BB-tree index
CHash index
DBitmap index
Attempts:
2 left
💡 Hint
Think about which index type helps with fast key/value lookups inside JSON data.
🔧 Debug
advanced
2:00remaining
Error When Using JSON Functions
Which option will cause an error when trying to use the JSONB containment operator '@>' on a JSON column?
PostgreSQL
SELECT * FROM test_table WHERE json_col @> '{"key": "value"}';
AThe query runs successfully and returns matching rows.
BThe query returns no rows but does not raise an error.
CThe query raises a syntax error due to wrong operator usage.
DThe query raises an error: operator does not exist: json @> json.
Attempts:
2 left
💡 Hint
Check if the operator '@>' is supported for the data type used.
🧠 Conceptual
expert
3:00remaining
When to Prefer JSON over JSONB
In which scenario is it better to use JSON instead of JSONB in PostgreSQL?
AWhen you want to avoid storing duplicate keys by default.
BWhen you need to preserve the exact input text including whitespace and key order.
CWhen you want faster query performance and indexing.
DWhen you want to use GIN indexes for complex queries.
Attempts:
2 left
💡 Hint
Think about what JSON preserves that JSONB does not.