📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Full Text Search

Full Text Search

7 min read
Full-text search uses tsvector and tsquery. Convert text with to_tsvector(), build a query with to_tsquery(), and match with @@. Add a GIN index on the tsvector column for fast search performance.

Full Text Search

-- Add tsvector column
ALTER TABLE articles ADD COLUMN tsv TSVECTOR
  GENERATED ALWAYS AS (to_tsvector('english', title || ' ' || body)) STORED;

CREATE INDEX idx_tsv ON articles USING GIN(tsv);

-- Search
SELECT title FROM articles
WHERE tsv @@ to_tsquery('english', 'postgresql & performance');