Reputation: 7376
I have a document in Couchbase:
{
"ResponseMessage": {
"0": {
"y2": "1",
"y1": "2"
},
"1": {
"x1": "499",
"x2": "O"
},
"CacheTimeOut": "0",
"ObjectID": "6632 87d7"
}
}
when I execute this query,
select ResponseMessage.0.y1 from `my-bucket`
I receive this response:
[
{
"code": 3000,
"msg": "syntax error - at 0",
"query": "select ResponseMessage.0.y1 from `my-bucket`"
}
]
If "0" is "a0" instead, it is does not return an error.
Is it possible to write reference the "0" JSON key name in a N1QL query?
Upvotes: 1
Views: 628
Reputation: 7376
0 is a literal number (in both JSON and N1QL). Therefore, you will need to escape it.
The solution is :
select ResponseMessage.`0`.y1 from `my-bucket`
Use this character ` (backtick) to escape
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/identifiers.html
Upvotes: 1