JSON vs JSONB, and views vs materialized views?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn JSON vs JSONB, and views vs materialized views?
Definition:
JSON stores JSON input text, while JSONB stores a processed representation that supports efficient operations and indexing. A view stores a query definition, whereas a materialized view stores the query's result for later reads. These are separate choices about data representation and precomputed results.
Key points:
-
JSON preserves input text; JSONB stores a processed format with useful indexing support.
-
A view stores a query; a materialized view stores its results and needs refreshing.
-
Use regular columns for data that needs strong relational rules and common filters.
-
A materialized view can become stale until refreshed; define freshness and refresh costs before relying on it for reports.
Interview point:
- Flexible fields and cached reports are useful, but frequently filtered business keys often belong in well-constrained relational columns.
Adapted from 05_SQL_POSTGRESQL.md · “JSON vs JSONB, and views vs materialized views?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.