tsquery:带空格的参数中的语法错误 [英] syntax error in tsquery : parameter with whitespaces
本文介绍了tsquery:带空格的参数中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建或替换函数search_questions(psearch文本)
RETURNS TABLE(questionid INTEGER)AS $ func $
BEGIN
return QUERY
SELECT DISTINCT(questions.publicationid)
FROM questions
WHERE to_tsvector(coalesce(questions.title ,''))@@ to_tsquery(psearch)
OR
publicationid IN(
SELECT DISTINCT(publications.publicationid)FROM publications WHERE to_tsvector(coalesce(publications.body,''))@ @ to_tsquery(psearch)
)
;
END
$ func $ LANGUAGE plpgsql;
但它只适用于单个单词参数。如果我搜索用户测试,它会返回
错误:tsquery中的语法错误:user test
有什么方法可以搜索带有空格的文本?
亲切的问候
解决方案
我发现如何解决它。
在这里它是
替换:
to_tsquery(psearch)
:
plainto_tsquery(psearch)
I have this Full-Text-Search function:
CREATE OR REPLACE FUNCTION search_questions(psearch text)
RETURNS TABLE (questionid INTEGER) AS $func$
BEGIN
return QUERY
SELECT DISTINCT (questions.publicationid)
FROM questions
WHERE to_tsvector(coalesce(questions.title, '')) @@ to_tsquery(psearch)
OR
publicationid IN (
SELECT DISTINCT(publications.publicationid) FROM publications WHERE to_tsvector(coalesce(publications.body, '')) @@ to_tsquery(psearch)
)
;
END
$func$ LANGUAGE plpgsql;
but it only works with a single word parameter. If I search for "user test", it returns
ERROR: syntax error in tsquery: "user test"
Is there any way to search for texts with whitespaces in it?
Kind regards
解决方案
I found how to solve it. Here it goes
Replace:
to_tsquery(psearch)
with:
plainto_tsquery(psearch)
这篇关于tsquery:带空格的参数中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文