Reputation: 4185
i currently setting up full text search in Postgresql database as described in this manual page: http://www.postgresql.org/docs/9.0/static/textsearch-tables.html
Currently i came out with this statement:
CREATE FUNCTION fts_update() RETURNS trigger AS $$
begin
new.tsv :=
to_tsvector('pg_catalog.english', coalesce(new.title,'')) ||
to_tsvector('pg_catalog.english', coalesce(new.description,'')) ||
to_tsvector('pg_catalog.english',
SELECT array_to_string(array_accum(name), ' ') FROM agencies where id = new.agency_id
);
return new;
end
$$ LANGUAGE plpgsql;
CREATE TRIGGER ftsupdate_trigger BEFORE INSERT OR UPDATE ON camps FOR EACH ROW EXECUTE PROCEDURE fts_update()"
Here i need to add some fields from another table to index, but Postgresql not allowing me:
PG::Error: ERROR: syntax error at or near "SELECT"
LINE 9: SELECT array_to_string(array_accum(name), ' ') FROM ...
Is there any good fix for this ?
Upvotes: 1
Views: 800
Reputation: 6480
I think all you need to do is wrap the select in brackets e.g.
select to_tsvector('english',(select array_to_string(array['one','two','three'],' ')));
Upvotes: 1