Peter Krauss
Peter Krauss

Reputation: 13920

How to interpret and access tsvector?

A data type tsvector is provided for storing preprocessed documents, along with a type tsquery for representing processed queries

But sometimes TSVECTOR is an array of words, sometimes a bag of word-position, sometimes a complex vector with positions and weights... Can I access the individual parts of its data structure? Example:

CREATE TABLE t ( tsv TSVECTOR );
INSERT INTO t VALUES 
  ('foo phrase'::TSVECTOR),
  ('second foo phrase'::TSVECTOR),
  ('third foo phrase'::TSVECTOR);

SELECT tsv FROM t WHERE "'foo' is the first word" -- how to do it??

Imagining that TSVECTOR has the same JSONb structure-access operators: we can access its structure by WHERE tsv->'foo'->0=1.

In the real life: I not see (here in the search-guide) a tsquery or direct operator that do it. And I not see (here in the General Guide) a complete TSVECTOR documentation, with a technical description of its real and complete internal structure.

Upvotes: 0

Views: 128

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246308

No, you cannot, that's not what it is built for.

You would have to write a PostgreSQL extension in C to access the internal structure of the data type. The cumbersome alternative is to parse the text representation.

Upvotes: 2

Related Questions