PostgreSQL Enterprise (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between `JSON` and `JSONB` data types?
junior LevelCode ExamplepostgresqlBasic
In Simple Words:
JSON(Textual): Stores the raw JSON text as a string verbatim, preserving whitespace, key ordering, and duplicate keys. Parsing occurs on every single query (slower search).JSONB(Binary - Recommended): Decomposes JSON into a parsed binary format:- Eliminates whitespace and duplicate keys.
- Significantly faster to process.
- Supports indexing via GIN indexes and containment operators (
@>,?,?&,?|)!
sql
-- Query JSONB with containment operator (Indexable!):
SELECT * FROM users WHERE metadata @> '{"role": "admin"}';