Couchbase Java LIKE 查询给出语法错误 - 在 %!(NOVERB)
Couchbase Java LIKE query giving syntax error - at %!(NOVERB)
下面是java代码:
QueryResult result = bucket.defaultScope().query("select * from _default d where d.name like %$nameParam%",
QueryOptions.queryOptions()
.parameters(JsonObject.create().put("nameParam", param)));
注意:“_default”是我的集合,如果我删除“like”和参数选项,查询就会工作 -> (select * from _default)
下面是错误:
com.couchbase.client.core.error.ParsingFailureException: Parsing of the input failed
{"completed":true,"coreId":"0x3c3d77b600000001","errors":[{"code":3000,"message":"syntax error - at %!(NOVERB)"}],"httpStatus":400,"idempotent":false,"lastDispatchedFrom":"127.0.0.1:57882","lastDispatchedTo":"127.0.0.1:8093","requestId":11,"requestType":"QueryRequest","retried":0,"service":{"bucket":"CartTest","operationId":"976e0085-c83f-4732-ad8e-7f8e258f52b8","scope":"_default","statement":"select * from _default d where d.name like %$nameParam%","type":"query"},"timeoutMs":75000,"timings":{"dispatchMicros":5828,"totalDispatchMicros":5828,"totalMicros":70213}}
目前我不想使用 FTS,只想知道 like 查询的正确语法?
你需要做的,
“select * from _default d where d.name like '%' || $nameParam || '%'”
其中“||”是字符串连接。 “like”后面的应该是字符串,“$”参数不能在字符串字面量中。
下面是java代码:
QueryResult result = bucket.defaultScope().query("select * from _default d where d.name like %$nameParam%",
QueryOptions.queryOptions()
.parameters(JsonObject.create().put("nameParam", param)));
注意:“_default”是我的集合,如果我删除“like”和参数选项,查询就会工作 -> (select * from _default)
下面是错误:
com.couchbase.client.core.error.ParsingFailureException: Parsing of the input failed
{"completed":true,"coreId":"0x3c3d77b600000001","errors":[{"code":3000,"message":"syntax error - at %!(NOVERB)"}],"httpStatus":400,"idempotent":false,"lastDispatchedFrom":"127.0.0.1:57882","lastDispatchedTo":"127.0.0.1:8093","requestId":11,"requestType":"QueryRequest","retried":0,"service":{"bucket":"CartTest","operationId":"976e0085-c83f-4732-ad8e-7f8e258f52b8","scope":"_default","statement":"select * from _default d where d.name like %$nameParam%","type":"query"},"timeoutMs":75000,"timings":{"dispatchMicros":5828,"totalDispatchMicros":5828,"totalMicros":70213}}
目前我不想使用 FTS,只想知道 like 查询的正确语法?
你需要做的, “select * from _default d where d.name like '%' || $nameParam || '%'” 其中“||”是字符串连接。 “like”后面的应该是字符串,“$”参数不能在字符串字面量中。