tsearch2 headline() query subselect help

Started by John Smithabout 19 years ago3 messagesgeneral
Jump to latest
#1John Smith
jayzee.smith@gmail.com

guys,
how'd i make this query work?
select headline(select column_1 from table_1 where
to_tsvector(column_1) @@ to_tsquery('ftp'),'ftp'::tsquery);
ERROR: syntax error at or near "select" at character 17

when i break it, it works fine, like so
# select headline('ftp sftp','ftp'::tsquery);
headline
----------
<b>ftp</b> sftp
(1 row)
# select column_1 from table_1 where to_tsvector(column_1) @@
to_tsquery('ftp');
column_1
----------
ftp sftp
(1 row)
where
# select column_1 from table_1 where column_index=1;
column_1
----------
ftp sftp
(1 row)

and how'd i add rank() to this query?
jzs
http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/

#2Jeff Davis
pgsql@j-davis.com
In reply to: John Smith (#1)
Re: tsearch2 headline() query subselect help

On Wed, 2007-01-10 at 19:14 -0500, John Smith wrote:

guys,
how'd i make this query work?
select headline(select column_1 from table_1 where to_tsvector
(column_1) @@ to_tsquery('ftp'),'ftp'::tsquery);
ERROR: syntax error at or near "select" at character 17

When passing a subselect as an argument to a function, you need to put
it in parenthesis, like so:

select myfunction((select ... from ...),'');

Regards,
Jeff Davis

#3Jeff Davis
pgsql@j-davis.com
In reply to: John Smith (#1)
Re: tsearch2 headline() query subselect help

On Wed, 2007-01-10 at 19:14 -0500, John Smith wrote:

guys,
how'd i make this query work?
select headline(select column_1 from table_1 where to_tsvector
(column_1) @@ to_tsquery('ftp'),'ftp'::tsquery);
ERROR: syntax error at or near "select" at character 17

After taking a closer look, why don't you just write it simply like:

select headline(column_1,'ftp'::tsquery) from table_1 where to_tsvector
(column_1) @@ to_tsquery('ftp');

If you do it as a subquery, the subquery can't return multiple values,
and it looks like you expect it to.

Jeff Davis