PSQLException:错误:tsquery中的语法错误 [英] PSQLException: ERROR: syntax error in tsquery
问题描述
必须避免哪些字符才能确保PSQLException:错误:tsquery 中的语法错误不会发生?
文档没有说明如何转义搜索字符串: http://www.postgresql.org/docs/8.3/static/datatype-textsearch.html
如果您希望将其用作短语/逐字或者包含语法中使用的字符,请在术语周围使用引号:
select to_tsquery '你好,嗨);记住,你不应该在你的条款中真的有疯狂的人物,因为他们不会去要匹配tsvector中的任何内容。
和
由tsquery解析器识别的(非令牌)字符是:
\0
(null),(
,)
,空格),
|
,&
,:
code> *!
。但是,如何标记您的查询应该基于您如何设置您的字典。在您的查询中,您可能不会想要很多其他字符,而不是因为它们会导致语法错误,而是因为这意味着您不会正确地对查询进行标记。
使用
plainto_tsquery
版本,如果它是一个简单的和
查询,并且您不想处理创建查询手动。Which characters must be avoided to make sure PSQLException: ERROR: syntax error in tsquery will not occur? The documentation does not say anything about how to escape the search string: http://www.postgresql.org/docs/8.3/static/datatype-textsearch.html
解决方案Use quotes around your terms if you want them as phrases/verbatim or they contain characters used in the syntax:
select to_tsquery('"hello there" | hi');
Bare in mind that you shouldn't really have crazy characters in your terms, since they are not going to match anything in the tsvector.
The (non-token) characters recognized by the tsquery parser are:
\0
(null),(
,)
,(whitespace),
|
,&
,:
,*
and!
. But how you tokenize your query should be based on how you have setup your dictionary. There are a great many other characters that you will likely not want in your query, not because they will cause a syntax error but because it means you are not tokenizing your query correctly.Use the
plainto_tsquery
version if it's a simpleAND
query and you don't want to deal with creating the query manually.这篇关于PSQLException:错误:tsquery中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!