Deb
Deb

Reputation: 753

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.

Upvotes: 0

Views: 193

Answers (2)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

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'

Upvotes: 1

Deb
Deb

Reputation: 753

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.

Upvotes: 0

Related Questions