I have the following tsvector update trigger for a tsvector column ‘user_tsv’ on a table that allows me to perform full text searches,
CREATE TRIGGER tsvector_user_update BEFORE INSERT OR UPDATE ON users
FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(user_tsv, 'pg_catalog.english', firstname, surname, email);
CREATE INDEX user_index_tsv ON users USING gin(user_tsv);
I have since added another column to the table that I want to include in this trigger, is there any way to update the trigger (and also the tsvector column) or do I need to drop the column / trigger and re-add them?
PostgreSQL 9.0
Thanks in advance
David
You don’t need to drop the column or the index, just drop and re-create the trigger and update any changed fields.
Drop the trigger with a regular
DROP TRIGGERstatement, then re-create it with the new column usingtsvector_update_trigger, all in the same transaction. NowUPDATE tablename SET user_tsv = ... WHERE new_column IS NOT NULLto update the column if you’ve already added columns. Examine the sources for the tsvector update trigger to find out the appropriate expression to use in the assignment.