简体   繁体   中英

Simple SQL select not working on DocumentDB

I have this very simple test document stored in DocumentDb:

{
  "DocumentDbTest_Countries": {
      "@country": "C24105130563",
      "@language": "C24105130563",
      "@countryCode": 1663405662,
      "@version": "2015-08-24T08:51:32:030.6165"
  },
  "id": "729607bd-38c5-2a96-0bc4-371a0a5bca4a"
}

Which I can find easily using the Document Explorer , and, also using the following Sql query in the Query Explorer :

SELECT * FROM DocumentDbTest_Countries c

But surprisingly when i run the following SQL query, it can't find the result:

SELECT * FROM DocumentDbTest_Countries c where c.country = 'C24105130563'

Can someone please guide me as to what I am doing wrong in the above SQL query?? I tried using double quotes instead of single but to no avail.

Since @ is a special character, you have to escape it with the Dictionary-like [] operator. For example, run the query as:

SELECT * FROM DocumentDbTest_Countries c where c["@country"] = 'C24105130563'

Found it. Its because of the @ sign present in the attributes.

Strangely I am using DocumentDB SDK to insert the data and those @ signs in the attributes are inserted by it. :(

Now have to find a way to remove the @ sign from the inserts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM