All TIL notes

Friday, 21 August 2026 · 1 min read

JSONB containment beats LIKE for tag columns

Store tags as a JSONB array and query with `@>` — it uses the GIN index and reads like what it means.

postgressql

select number, tags
from dives
where tags @> '["cave", "scooter"]'::jsonb;

@> means “contains”. With create index on dives using gin (tags) this is an index scan. The equivalent tags::text like '%cave%' matches cavern too and never uses an index.