0

I tried in many ways to send a tuple parameter like: {"name": "@p", "value": tuple(['a','b']) }

to the query, which is simple as:

select * from c where c.p in @p

I always get a syntax error or no results. when i'm copying the parameter from the console to a query i get the results as expected.

help?

1 Answer 1

1

According to the section Request Body of the REST reference Querying DocumentDB resources using the REST API, the requirement for the value of the parameter as below.

parameters Required. A JSON array of parameters specified as name value pairs. The parameter array can contain from zero to many parameters.Each parameter must have the following values:name: the name of the parameter. Parameter names must be valid string literals and begin with ‘@’. value: the value of the parameter. Can be any valid JSON value (string, number, object, array, Boolean or null).

So you can pass a Python tuple parameter for a DocumentDb query, please using an array like ['a', 'b'] instead of tuple(['a', 'b']), or just convert it via the code like list(tuple(['a', 'b'])).


Update:

I reviewed the source code of pydocumentdb and found the parameters in the request body of the DocumentDb query is serialized by using the method json.wraps which will serialize the tuple to list. For example, execute the code json.wraps(('a', 'b')), then get the result ['a', 'b']. So if using pydocumentdb, the only way for your case is that directly embed the tuple value into the query string.

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

2 Comments

Thanks for the answer Peter, I tried using an array. but it does not seems to work. I used tuple just to get the form of where c.p IN ('a,'b','c'). To which form is the array being translated to?
@Amitbe Unfortunately, I tried to solve the issue, but failed because of the content I updated on my post above.

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.