tsearch2 text::TSVECTOR cast not working for me on Pg 8.1.6

Started by James Reynoldsabout 18 years ago2 messagesgeneral
Jump to latest
#1James Reynolds
jamex@taraketh.net

Hi,

I want to convert a TEXT string that I am mangling to TSVECTOR with a cast.
I am using Postgresql 8.1.6 and tsearch2.

According to the documentation this should work although I am getting an
ERROR.

tsearch2 reference on www.sai.msu.su says that

text::TSVECTOR RETURNS TSVECTOR

FWIW, I am using regexp_replace to just take out the first occurrence of
each lexeme and then trying to cast back into a tsvector.

EG:

SELECT replace(
regexp_replace(
textin(
tsvector_out(
to_tsvector('default', coalesce(l.comments, ''))
)
)::TEXT
, '(:\\d+[ABCD]*)(\\,\\d+[ABCD]*)*', '\\1', 'g')
, '''', '')::tsvector
FROM listings l LIMIT 1;

ERROR: cannot cast type text to tsvector

What is interesting is that a basic select works probably because the
pseudo type 'cstring' is in effect.

select 'To a Vector'::TSVECTOR;
tsvector
-------------------
'a' 'To' 'Vector'
(1 row)

Time: 3.297 ms

Any ideas on how to get back to a cstring so that it will work
OR
how to make the text::TSVECTOR cast work?

Cheers,
James

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: James Reynolds (#1)
Re: tsearch2 text::TSVECTOR cast not working for me on Pg 8.1.6

"James Reynolds" <jamex@taraketh.net> writes:

I want to convert a TEXT string that I am mangling to TSVECTOR with a cast.
I am using Postgresql 8.1.6 and tsearch2.

According to the documentation this should work although I am getting an
ERROR.
tsearch2 reference on www.sai.msu.su says that
text::TSVECTOR RETURNS TSVECTOR

Seems to be a documentation mistake, since there's no CREATE CAST
anywhere in the tsearch.sql file (either in 8.1 or later versions).

I think you want to use to_tsvector().

regards, tom lane