问题描述
Couchbase查询应在过滤器( where
子句.)中支持属性名称的任何字符串.
Couchbase queries should support any String for property-name in a filter ( where
clause.)
但是下面的查询未返回任何 fieldNames
"7","a",#",&",",?" 代码>.它适用于
fieldName
a
的值.
But the query below returns no values for any of the fieldNames
"7", "a", "#", "&", "", "?"
. It does work for values for fieldName
a
.
请注意,我使用的是Java DSL API,而不是直接使用N1ql.
Note that I'm using the Java DSL API, not N1ql directly.
OffsetPath statement = select("*").from(i(bucket.name())).where(x(fieldName).eq(x("$t")));
JsonObject placeholderValues = JsonObject.create().put("t", fieldVal);
N1qlQuery q = N1qlQuery.parameterized(statement, placeholderValues);
N1qlQueryResult result = bucket.query(q);
但是我的存储桶确实有每个这些JsonObject,包括那些具有不寻常属性名称的JsonObject,如未过滤的查询所示:
But my bucket does have each of these JsonObjects, including those with unusual property names, as shown by an unfiltered query:
{"a":"a"}
{"#":"a"}
{"&":"a"}
{"":"a"}
{"?":"a"}
如何在查询中转义属性名称或以其他方式支持这些合法名称?
How do I escape property names or otherwise support these legal names in queries?
(此问题与另一个有关,但这与值有关,而与字段名有关.)
(This question relates to another one, but that is about values and this is about field names.)
推荐答案
字段名称被视为标识符.因此,需要反引号来逃避它们:
The field name is treated as an identifier. So, back-ticks are needed to escape them thus:
select("*").from(i(bucket.name())).where(x("`" + fieldName + "`").eq(x("$value"))
参数化为 $ value
,当然
这篇关于在Couchbase Java查询DSL中,如何过滤不是来自ASCII字母的属性名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!