Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cosmos db sql query with non alphanumeric field name

My data structure in cosmosdb is next

   {
      "_id": {
      "$oid": "554f7dc4e4b03c257a33f75c"
      },
      .................
   }

and I need to sort collection by $oid field. How should I form my sql query?

Normal query SELECT TOP 10 * FROM collection c ORDER BY c._id.filedname not works if fieldname starts with $ like $oid.

I am using query explorer from azure portal.

like image 422
Anton Putau Avatar asked Sep 14 '17 09:09

Anton Putau


1 Answers

To use a special character, like $, you need to use bracket notation:

SELECT c._id FROM c
order by c._id["$oid"]

You can do this with each property in the hierarchy, so the following also works:

SELECT c._id FROM c
order by c["_id"]["$oid"]
like image 104
David Makogon Avatar answered Nov 03 '22 14:11

David Makogon