Is it possible to convert a Postgres column of type tsvector back to a regular TEXT column?
I assume it's lossy, but how can I create a new column from my existing tsvector column with type TEXT? Having it create multiple variants of words in the TEXT column is fine.
All of my inserts to the existing column were done with to_tsvector so I don't have the original raw TEXT.
I can do tsvector_to_array to convert a tsvector back to a string array. I can then convert the array to a string with array_to_string.
e.g:
SELECT array_to_string(tsvector_to_array(ts_column), ' ') FROM mytable
However this doesn't generate the full words, only the lexemes (and I'd want the full words even if lossy).
Here ya go. It works for all my test cases.
As a note, I am a total PL/pgSQL novice. But I just wrote the logic in Javascript and then ChatGPT obligingly converted it to PL/pgSQL. It's a crazy world we live in nowadays. Javascript implementation for reference: