为什么在这个 Couchbase N1QL 查询中出现语法错误 - 为 0?
Why is there a syntax error - at 0 in this Couchbase N1QL query?
我在 Couchbase 中有一个文档:
{
"ResponseMessage": {
"0": {
"y2": "1",
"y1": "2"
},
"1": {
"x1": "499",
"x2": "O"
},
"CacheTimeOut": "0",
"ObjectID": "6632 87d7"
}
}
当我执行这个查询时,
select ResponseMessage.0.y1 from `my-bucket`
我收到了这个回复:
[
{
"code": 3000,
"msg": "syntax error - at 0",
"query": "select ResponseMessage.0.y1 from `my-bucket`"
}
]
如果“0”是 "a0",则不会 return 错误。
是否可以在 N1QL 查询中写入引用“0”JSON 键名?
0 是一个文字数字(在 JSON 和 N1QL 中)。因此,您需要对其进行转义。
解决方法是:
select ResponseMessage.`0`.y1 from `my-bucket`
使用这个字符`(反引号)转义
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/identifiers.html
我在 Couchbase 中有一个文档:
{
"ResponseMessage": {
"0": {
"y2": "1",
"y1": "2"
},
"1": {
"x1": "499",
"x2": "O"
},
"CacheTimeOut": "0",
"ObjectID": "6632 87d7"
}
}
当我执行这个查询时,
select ResponseMessage.0.y1 from `my-bucket`
我收到了这个回复:
[
{
"code": 3000,
"msg": "syntax error - at 0",
"query": "select ResponseMessage.0.y1 from `my-bucket`"
}
]
如果“0”是 "a0",则不会 return 错误。
是否可以在 N1QL 查询中写入引用“0”JSON 键名?
0 是一个文字数字(在 JSON 和 N1QL 中)。因此,您需要对其进行转义。
解决方法是:
select ResponseMessage.`0`.y1 from `my-bucket`
使用这个字符`(反引号)转义
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/identifiers.html