Hi,
Couchbase Server: 4.5.0-2601 Community Edition
I’m having problems with a query where I’m trying to use placeholders within backticks because I’m trying to use a placeholder as an object key, e.g.
AND subObj.`$1` = "bar"
If you could tell me how I might workaround this issue, I’d be very greatful.
Thanks
Glen
Test data:
UPSERT INTO survey (KEY, VALUE) VALUES ("com.example_test_123",
{
"id": "123",
"type": "test",
"subObj": {
"3905a0ca-dd4c-4359-8c7e-5fee9698e999": "foo",
"3131d46c-9844-4ea1-b2be-86f75f8df11c": "bar",
"1c8bc271-b898-45b7-bcea-3d74a53827ec": "baz"
}
})
I’ve been trying to use positional args in the Go SDK to query on the values for certain subObj keys, but it hasn’t been working. Further investigation, with the REST API shows that it’s not the SDK, but something in the API / Core.
Here is a query that works:
curl -X POST -d 'statement=SELECT * FROM survey WHERE type%3D"test" AND subObj.`3131d46c-9844-4ea1-b2be-86f75f8df11c` %3D "bar"&args=[]&creds=[{"user": "Administrator"%2C "pass":"password"}]' "http://127.0.0.1:8093/query/service"
Results:
{
"requestID": "df1caecf-9c46-4f71-b570-9139e5e080e9",
"signature": {
"*": "*"
},
"results": [
{
"survey": {
"id": "123",
"subObj": {
"1c8bc271-b898-45b7-bcea-3d74a53827ec": "baz",
"3131d46c-9844-4ea1-b2be-86f75f8df11c": "bar",
"3905a0ca-dd4c-4359-8c7e-5fee9698e999": "foo"
},
"type": "test"
}
}
],
"status": "success",
"metrics": {
"elapsedTime": "156.611612ms",
"executionTime": "156.578888ms",
"resultCount": 1,
"resultSize": 356
}
}
And here is one that doesn’t:
curl -X POST -d 'statement=SELECT * FROM survey WHERE type%3D"test" AND subObj.`%241` %3D "bar"&args=["3131d46c-9844-4ea1-b2be-86f75f8df11c"]&creds=[{"user": "Administrator"%2C "pass":"password"}]' "http://127.0.0.1:8093/query/service"
Results:
{
"requestID": "24aba27b-6518-4ad2-9584-d2c266d9d566",
"signature": {
"*": "*"
},
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "171.882536ms",
"executionTime": "171.84551ms",
"resultCount": 0,
"resultSize": 0
}
}