'Azure Cosmos DB Input Binding - cannot pass OFFSET and LIMIT values as params?

I'm experiencing an issue with trying to dynamically pass the values for OFFSET and LIMIT as query params to my CosmosDB trigger.

If I hardcode the values for these two into the query, it works as expected.

However, with this code:

 {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "v1/query/properties",
      "methods": [
        "post"
      ]
    },
    {
      "name": "propertiesInquiryInput",
      "type": "cosmosDB",
      "databaseName": "property",
      "collectionName": "discovery",
      "connectionStringSetting": "CosmosDBConnectionString",
      "direction": "in",
      "leaseCollectionName": "leases",
      "sqlQuery": "SELECT * FROM c WHERE c.country={country} OFFSET {pageNo} LIMIT {perPage}"
    },

I get the following failure upon execution:

System.Private.CoreLib: Exception while executing function: Functions.queryProperties. Microsoft.Azure.DocumentDB.Core: Message: {"errors":[{"severity":"Error","location":

{"start":48,"end":55},"code":"SC2062","message":"The OFFSET count value exceeds the maximum allowed value."},
{"severity":"Error","location":{"start":62,"end":70},"code":"SC2061","message":"The LIMIT count value exceeds the maximum allowed value."}]}

I'm relatively new to Azure services and their patterns, so perhaps I'm missing something obvious here. I've tried sending these values as a JSON object via POST and as query params via a GET request. Nothing seems to work.

I'm also not aware of a way to view what the SQL query that IS being fired off, so as to perhaps debug it from that angle. Any guidance in the right direction would be appreciated.

Update:

Adding function body for clarity:

module.exports = async function (context, req) {
    const results = context.bindings.propertiesInquiryInput;
    !results.length && context.done(null, { status: 404, body: "[]", });

    const body = JSON.stringify(results.map(data => reshapeResponse(data));

    return context.done(null, { status: 200, body });
}



Solution 1:[1]

In addition to the original question:

Got the same exception message with parametrised query and azure.cosmos=4.2.0 pypi package for python.

Case to reproduce:

query = f"""
SELECT *
FROM c
WHERE ...
AND c.run.submittedBy = @author
OFFSET 0 LIMIT @exp_limit
"""

items = list(cdb_container.query_items(
    query=query,
    parameters=[
        {"name":"@exp_limit", "value": f"{num_of_experiments}"}, # can't pass as param due to `The LIMIT count value exceeds the maximum allowed value.`
        {"name":"@author", "value": f"{submitter}"},
    ],
    enable_cross_partition_query=True
))

Workaround (with formatted string for the query):

num_of_experiments = 10
query = f"""
SELECT *
FROM c
WHERE ...
AND c.run.submittedBy = @author
OFFSET 0 LIMIT {num_of_experiments}
"""

Omitted not-related parameters in WHERE statement for example purpose. Might be helpful for someone who is struggling with a similar case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sysanin