# pg_trgm — Postgres extension

> Fuzzy text search and fast LIKE and ILIKE with trigram indexes.

Source: https://scribase.com/extensions/pg_trgm

Category: Text search and indexing. Version: 1.6. Optional, enabled per project.

## About

pg_trgm splits text into three-character pieces and compares the sets. That gives typo-tolerant matching (similarity, the % operator) and, with a GIN trigram index, fast LIKE and ILIKE searches with a leading wildcard, which a normal B-tree index cannot serve.

## Enable it

```sql
create extension if not exists pg_trgm with schema extensions;
```

## Example

```sql
create index posts_title_trgm on posts using gin (title gin_trgm_ops);

-- uses the index
select id, title from posts where title ilike '%postgres%';

-- typo-tolerant ranking
select title, similarity(title, 'postgress') as score
from posts
where title % 'postgress'
order by score desc
limit 10;
```

Upstream: https://www.postgresql.org/docs/17/pgtrgm.html