Databases
sql
Beginner
PostgreSQL Full-Text Search
Set up and query full-text search on a PostgreSQL table with ranking.
sql
ALTER TABLE modules ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (to_tsvector('english', title || ' ' || description)) STORED;
CREATE INDEX idx_fts ON modules USING GIN(search_vector);
SELECT title, ts_rank(search_vector, query) AS rank
FROM modules, to_tsquery('english', 'nginx & deploy') query
WHERE search_vector @@ query
ORDER BY rank DESC;
Prerequisites
- PostgreSQL >= 12
Pro Tips
- → Use websearch_to_tsquery for user-input queries.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- sql
- Level
- Beginner
- Read time
- 4 min
- Published
- Feb 2025
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
MySQL Replication Status Check
Script to check MySQL/MariaDB replication lag and alert if it exceeds threshold.
sql
·
Intermediate
DB Connection Pool Monitor
Query to check active connections, idle connections and pool usage in PostgreSQL.
sql
·
Intermediate
Cursor-based Pagination Query
Implement cursor-based (keyset) pagination in SQL — faster than OFFSET for large tables.
sql
·
Intermediate