Full text search in PostgreSQL with "to_tsvector" for all columns

1.5k views Asked by At

I am adding one column in table to create index for search with to_tsvector.

My question is how can I mention all comumns in to_tsvector(?).

I know by using all names in to_tsvector(Column1 ||""||Column2||""||Column3......); it can be done.

In case of 50+ columns its difficult to write name of each column, so how to write to_tsvector(?) in short so by default all comaumns are considered for to_tsvector.

ALTER TABLE from "POC1_Schema"."POC1_Table"
ADD COLUMN document tsvector;

UPDATE from "POC1_Schema"."POC1_Table"
SET document= to_tsvector(Column1|| ' ' ||Column2|| ' ' ||Column3|| ' ' ||Column4|| ' ' ||Column5|| ' ' ||Column6);

CREATE INDEX document_idx
  ON "POC1_Schema"."POC1_Table"
  USING GIN (document_with_idx);

select *
from from "POC1_Schema"."POC1_Table"
where document @@ to_tsquery('READY');
0

There are 0 answers