CREATE OR REPLACE FUNCTION public.table_vector_update()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'UPDATE') THEN
IF ( OLD.name <> NEW.name or OLD.text <> NEW.text or OLD.number <> NEW.number) THEN
NEW.fts=setweight( coalesce( to_tsvector('ru', NEW.name),''),'A') || ' ' ||
setweight( coalesce( to_tsvector('ru', NEW.text),''),'B') || ' ' ||
setweight( coalesce( to_tsvector('ru', NEW.number),''),'D');
RETURN NEW;
ELSE
RETURN NEW;
END IF;
ELSIF (TG_OP = 'INSERT') THEN
NEW.fts=setweight( coalesce( to_tsvector('ru', NEW.name),''),'A') || ' ' ||
setweight( coalesce( to_tsvector('ru', NEW.text),''),'B') || ' ' ||
setweight( coalesce( to_tsvector('ru', NEW.number),''),'D');
RETURN NEW;
END IF;
RETURN NULL;
END;