Postgres features interviews ask · mid
JSONB in Postgres
JSONB stores JSON in a parsed binary form that can be queried with operators like ->, ->> and @> and indexed with GIN, which is good for flexible attributes, but data you filter, join or constrain on often should still be real columns.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- json keeps the exact text; jsonb stores a parsed form (no duplicate keys, key order not kept), is faster to query and can be indexed. Use jsonb.
- Operators: -> returns JSON, ->> returns text (attrs->>'color'), #>> for paths, @> containment (attrs @> '{"color": "red"}'), ? key exists; jsonb_set to update a key.
- Indexes: GIN on the whole column supports @>, ?, ?|, ?& (jsonb_path_ops is smaller but only supports @>); or a B-tree expression index on one hot key ((attrs->>'brand')).
- Good fits: product attributes that vary by category, user preferences, third-party payloads (webhook bodies) you keep for audit.
- Poor fits: anything with relationships, constraints, frequent updates of single keys in large documents (the whole value is rewritten), or reporting.
- Validate the shape in the application (zod) or with CHECK constraints; Postgres will not enforce a schema for you.
The red pen
Common traps: mistake → fix
Mistake: JSONB makes Postgres a schemaless MongoDB, so skip modelling
Fix: you lose constraints and easy joins; keep core fields as columns.
Mistake: attrs->'price' > 100 compares numbers
Fix: -> returns jsonb and ->> returns text; cast explicitly ((attrs->>'price')::numeric).
Easy to hard
Questions interviewers ask, easy to hard
- json vs jsonb?
- How do you query and index a JSONB column?
- When would you use JSONB instead of columns?
- Product catalogue with different attributes per category: columns, EAV table or JSONB?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.