0PricingLogin
SQL Academy · Lesson

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

  1. Trigram Search (pg_trgm) for Fuzzy Matching
  2. Full-Text Search with tsvector and GIN
  3. Geospatial Indexing with PostGIS
  4. Vector Search with pgvector
← Back to SQL Academy