JSON & JSONB
◈ 2 cardsStore and query semi-structured data — a job-critical Postgres skill.
Semi-structured data
jsonb stores JSON in an efficient binary form you can index and query. Each book has an attributes jsonb like {"format":"hardcover","pages":320}. Reach inside it:
attributes->'pages'— get the value as jsonbattributes->>'format'— get it as text (note the double>)(attributes->>'pages')::int— text, then cast to a numberattributes @> '{"format":"ebook"}'— containment (GIN-indexable, fast)
SELECT title FROM books WHERE attributes @> '{"format":"ebook"}';