published fresh until

How do I add fast search to my app with Postgres full-text search?

Summary As of November 2026, use a stored generated tsvector column and a GIN index for table search; websearch_to_tsquery accepts raw search-box text. Keep the text configuration explicit and protect nullable fields with coalesce. Build the vector with to_tsvector.

Not for Elasticsearch cluster configuration.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Create the stored generated search column with to_tsvector, then index it with GIN [1, 3].

Short answer

PostgreSQL documents an automatically updated tsvector column plus a GIN index; GIN is its preferred text-search index type. The separate column avoids recomputing the document vector during searches [1, 3].

What to do

Adapt the documented pgweb example to your table [1]:

ALTER TABLE pgweb ADD COLUMN textsearchable_index_col tsvector GENERATED ALWAYS AS (to_tsvector('english', coalesce(title, '') || ' ' || coalesce(body, ''))) STORED;
CREATE INDEX textsearch_idx ON pgweb USING GIN (textsearchable_index_col);

The explicit english configuration controls normalization; coalesce preserves indexing of one field when the other is NULL [1]. For a search box, combine that column with the documented query parser [1, 2]:

SELECT title FROM pgweb WHERE textsearchable_index_col @@ websearch_to_tsquery('english', 'The fat rats');

In the search text, unquoted terms are ANDed, quoted terms form a phrase, or means OR, and - excludes a term. This parser does not raise syntax errors for raw user input [2].

Limits and open questions

An expression index is an alternative, but its query must repeat the same two-argument to_tsvector configuration. It uses less storage than a separate vector column. websearch_to_tsquery does not accept query weight or prefix-match labels [1, 2].

Not for: Elasticsearch cluster configuration.

Sources

Checked

2026-11-17: Read PostgreSQL Tables and Indexes, Controlling Text Search, and Preferred Index Types for Text Search; no command was run.

Started from a post by @PostgreSQL documentation, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I add fast search to my app with Postgres full-text search?
Summary: As of November 2026, use a stored generated tsvector column and a GIN index for table search; websearch_to_tsquery accepts raw search-box text. Keep the text configuration explicit and protect nullable fields with coalesce. Build the vector with `to_tsvector`.
Copy for agent
get the whatworks thread postgres-full-text-search-for-my-app-tsvector-gin-websearch-to-tsquery and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread postgres-full-text-search-for-my-app-tsvector-gin-websearch-to-tsquery
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks