This guide demonstrates how to implement full-text search in PostgreSQL with Drizzle and generated columns. A generated column is a special column that is always computed from other columns. It is useful because you don’t have to compute the value of the column every time you query the table:
schema.ts
migration.sql
When you insert a row into a table, the value of a generated column is computed from an expression that you provide when you create the column:
This is how you can implement full-text search with generated columns in PostgreSQL with Drizzle ORM. The @@ operator is used for direct matches:
This is more advanced schema with a generated column. The search column is generated from the title and body columns and setweight() function is used to assign different weights to the columns for full-text search.
This is typically used to mark entries coming from different parts of a document, such as title versus body.
schema.ts
migration.sql
This is how you can query the table with full-text search: