'how to make my trigger function to perform asyncronously to update tsvector field?
I am new to postgres. Suppose i have two models AnimalType and Animal. And i have search_vector field of type tsvector in Animal model. i created trigger that whenever i update a AnimalType row, the searchvector should update itself for every Animal related to that AnimalType.
CREATE OR REPLACE FUNCTION update_animal_type()
RETURNS TRIGGER
LANGUAGE plpgsql AS $$
BEGIN
UPDATE animal SET search_vector = NULL
WHERE animal_type_id = NEW.id;
RETURN NEW;
END;
$$;
CREATE TRIGGER animal_type_update_trigger
AFTER UPDATE OF animal_type_name ON animal_type
FOR EACH ROW EXECUTE PROCEDURE update_animal_type();
It takes a lot of time to update a single animal type row when we have large number of animals related to that particular animal type. Is this behaviour is synchronous or asynchronous? If it is synchronous how can i make it to behave asynchronous?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
