Skip to main content
InterviewHubPRO
Section Overview
Q39

Question 39 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

78%
PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

JSONB Deep Dive: High-Performance Semi-Structured Storage.

senior LevelMost AskedCode ExampleFormsPerformance

In Simple Words:

  • json vs jsonb: json stores the exact raw text string (preserving whitespace and key duplicates, slower to query). jsonb parses JSON into a decomposed binary format, eliminating duplicate keys and enabling indexing.
  • JSONB Operators:
    • data -> 'user' (Returns JSON)
    • data ->> 'user' (Returns text)
    • data @> '{"role": "admin"}' (Containment check, utilizes GIN index!)
sql
-- Creating GIN index on JSONB column for instant sub-millisecond lookups
CREATE INDEX idx_users_metadata_gin ON users USING GIN (metadata jsonb_path_ops);

-- Accelerated by GIN index
SELECT * FROM users WHERE metadata @> '{"department": "Engineering", "active": true}';