In Couchbase Java Query DSL, how do I filter for property-names that are not from the ASCII alphabet?

倖福魔咒の 提交于 2019-12-11 05:38:38

问题


Couchbase queries should support any String for property-name in a filter ( where clause.)

But the query below returns no values for any of the fieldNames "7", "a", "#", "&", "", "?". It does work for values for fieldName a.

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);

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.)


回答1:


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"))

with parameterization of $value, of course



来源:https://stackoverflow.com/questions/55338567/in-couchbase-java-query-dsl-how-do-i-filter-for-property-names-that-are-not-fro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!