Trigram Search (pg_trgm) for Fuzzy Matching
Find similar strings with the pg_trgm extension, GiST/GIN trigram indexes, and similarity().
Why Trigrams?
LIKE %word% can't use a B-tree index. Trigrams ("3-character substrings") combined with GIN/GiST give you fast fuzzy and substring search.
Enable the Extension
pg_trgm ships with PostgreSQL contrib:
CREATE EXTENSION IF NOT EXISTS pg_trgm;All lessons in this course
- Trigram Search (pg_trgm) for Fuzzy Matching
- Full-Text Search with tsvector and GIN
- Geospatial Indexing with PostGIS
- Vector Search with pgvector