I hope you all are having a good Sunday. I am working on an application using Phoenix, Apollo, graphql and react. One of features in the app is text search. I am using postgresql ‘a full text search. It is working fine in the query to pull data. I want to use to_tsvector when inserting a new record in the table.
Currently I am updating the search tokens column using a database trigger. I want to avoid using database triggers.
Is there any example how to use to_tsvector in a changeset?
As @dbern commented above you could use a generated column. The column would be updated automatically whenever the column(s) it depends on update.
A generated column is a special column that is always computed from other columns. Thus, it is for columns what a view is for tables. There are two kinds of generated columns: stored and virtual. A stored generated column is computed when it is written (inserted or updated) and occupies storage as if it were a normal column. A virtual generated column occupies no storage and is computed when it is read. Thus, a virtual generated column is similar to a view and a stored generated column is similar to a materialized view (except that it is always updated automatically). PostgreSQL currently implements only stored generated columns.