Surya
Surya

Reputation: 45

How to query a property with a dash in CosmosDB SqlAPI?

Query: I wanted to get the list of records for all people born in the month of March.

{
    "details": {
        "state": "CA",
        "city": "San Fransisco",
        "date-of-birth": { // there is a "-" in the key
            "month": "March",
            "year": "2000"
        }
    },
    "personId": "person1",
    "id": "id1"
},
{
    "details": {
        "state": "CA",
        "city": "San Jose",
        "date-of-birth": { // there is a "-" in the key
            "month": "April",
            "year": "2000"
        }
    },
    "personId": "person2"
    "id": "id2"
}

I was hoping that the SQL Query would be like this, but got an error :

select * from c where c.details['date-of-birth'['month']] = "March"

Can someone help me out with the query? I did try to look at the docs but got a little bit confused.

Upvotes: 1

Views: 142

Answers (1)

Hasan Savran
Hasan Savran

Reputation: 393

Try this

select * from c where c.details['date-of-birth'].month = "March"

Upvotes: 2

Related Questions