0

I'm trying to update a value of document created on cosmosDB azure using sql api. The problem is that the requests update/ delete/ Insert don't work.

client.queryDocuments(
    collectionUrl,
    UPDATE tableC
    SET prev = 12
    WHERE condition
).toArray((err, results) => {
    if (err) res.json({ 'A': 12 });
    else {
        res.json({ 'A': 15});
    }
})
1
  • I believe it is a valid question that should not be downvoted. It's not obvious that the term "SQL API" is not the same as commonly known (ANSI) SQL and jumping to expectation that it should support CUD from CRUD may happen to others as well. Commented May 22, 2018 at 9:53

2 Answers 2

2

CosmosDB SQL is not ANSI SQL implementation. It supports just querying in a somewhat similar manner, but it's not the same thing.

From Introduction to Azure Cosmos DB: SQL API:

Azure Cosmos DB supports querying documents using a SQL language, which is rooted in the JavaScript type system, and expressions with support for relational, hierarchical, and spatial queries. The Azure Cosmos DB query language is a simple yet powerful interface to query JSON documents. The language supports a subset of ANSI SQL grammar and adds deep integration of JavaScript object, arrays, object construction, and function invocation.

So basically CosmosDB takes some syntax rules and conventions from SQL but when you look closer it's another beast. Ansi SQL contains things CosmosDB SQL API does not have and cosmosDB SQL has things ANSI SQL does not have.

Why?

Not having support for entire ANSI SQL makes sense, as SQL was designed for relational data manipluation needs. CosmosDB is not a relational database and its change model is working with documents as the changeable units, not individual fields or sets. In DoucmentDB you add one entire document, update one entire document, or delete one entire document. As long as this stands, it does not need the complexity of traditional SQL insert/update/delete syntax.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank's for your help, but if I want a database on Azure where i can modify, what can i use ?
You CAN modify documents in documentDB, just not by SQL syntax. In documentDB if you want to modify a field, you update the entire document. See: learn.microsoft.com/en-us/azure/cosmos-db/…
@MezianiAmina did you get your problem solved? If so, then you could mark the answer as accepted.
0

CosmosDB's flavor of SQL only supports querying.

You cannot use data manipulation SQL.

1 Comment

For anyone else who's as confused as I was, it's important to understand the distinction between the SQL API and the Cosmos DB SQL syntax. For some reason known only to Microsoft, the core/native API for Cosmos DB is called the SQL API and this most certainly does allow create/update/delete, but just not with SQL syntax. For instance learn.microsoft.com/en-us/azure/cosmos-db/sql/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.