Search code examples
postgresqlsplittsvector

split strings inside a tsvector


I have a tsvector with values of strings(text) inside it. I want to preform the split_part() function of postgres for each element inside the tsvector and to get a table with those values. Is it possible?

Example:

tsvector: 'hello' 'world' 'thank you'

output after performing split_part(elementOfTsvector, 'o', 1) on each element:

Table:

'hell'

'w'

'thank y'


Solution

  • You can use unnest() on tsvectors to get lexemes.

    select split_part(lexeme, 'o', 1) from unnest('hello world ''thank you'''::tsvector);