Search code examples
odataazure-cosmosdb

CosmosDB Table API with odata contains filter


Can we use odata 'contains' query option with table api on CosmosDB?

CosmosDB sql api supports 'contains' statement but it is not clear if we can use 'contains' filter with table api (odata).

https://learn.microsoft.com/tr-tr/rest/api/storageservices/querying-tables-and-entities

According to docs, Azure table storage does not support contains filter but we know that CosmosDB has a native support to it.


Solution

  • Both Cosmos DB's Table API and Azure Table storage support the exact same OData operators as defined in https://learn.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities#supported-query-options and contains isn't on the list so we don't support it via the Table API.

    Keep in mind that the Table API is intended for people with existing working code against Azure Table storage who are looking for better performance, geographic distribution, etc. If you are looking for net new features then we would encourage you to investigate the SQL API rather than Table API as we make continuous investments in SQL API. For Table API our goal is just to match the protocol functionality of Azure Table storage, not exceed it.

    That having been said, there is a work around. Table API is implemented as a wrapper on SQL API. So it's possible to point a SQL API client at the table container and use normal SQL API queries. However be aware that the format of the data you will see will be odd. We use our own internal storage conventions for storing table data. Also do not make any updates/writes via the SQL API to a Table API container as this can corrupt your data.

    Thanks,

    Yaron Y. Goland
    Principal Program Manager
    Cosmos DB, Microsoft