我有一列标签,称为标签,这是varchars的数组类型。 如何修改此触发器以包含这些单词?
create
trigger tsvectorupdate before insert
or update
on
public.records for each row execute procedure tsvector_update_trigger( 'tsv',
'pg_catalog.english',
'title',
'text',
'caption',
'location_name')
答案 0 :(得分:0)
好-手册有答案
CREATE function update_tsv() RETURNS trigger AS $$
begin
new.tsv :=
setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
setweight(to_tsvector('pg_catalog.english', coalesce(new.caption,'')), 'A') ||
setweight(to_tsvector('pg_catalog.english', coalesce(new.text,'')), 'A') ||
setweight(to_tsvector('pg_catalog.english', coalesce(new.location_name,'')), 'A') ||
setweight(to_tsvector('pg_catalog.english',
coalesce(array_to_string(new.tags,','),'')), 'A');
return new;
end
$$ LANGUAGE plpgsql;
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON records FOR EACH ROW EXECUTE PROCEDURE update_tsv();