These trigger functions automatically compute a tsvector column from one or more textual columns,
under the control of parameters specified in the CREATE TRIGGER command. An example of their use
is:

CREATE TABLE messages (
title       text,
body        text,
tsv         tsvector
);
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON messages FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(tsv, 'pg_catalog.english', title, body);
INSERT INTO messages VALUES('title here', 'the body text is here');
SELECT * FROM messages;
title    |         body          |            tsv
------------+-----------------------+----------------------------
title here | the body text is here | 'bodi':4 'text':5 'titl':1
SELECT title, body FROM messages WHERE tsv @@ to_tsquery('title & body');
title    |         body
------------+-----------------------
title here | the body text is here

Having created this trigger, any change in title or body
will automatically be reflected into tsv, without the application having to worry
about it.

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。