Sajeetharan
Sajeetharan

Reputation: 222582

Cosmosdb : "message":"Syntax error, invalid numeric value token '4d5f'." error

I am trying to query some information from the document db, it used to work earlier when we have id field , I recently replaced with Guid field and when we run the following query it throws the error as follows

Code:

  queryString = string.Format(
                        "SELECT f.keys.Timestamp,f.keys.selectedFieldId FROM {0} f WHERE f.logevent = '{1}' AND f._ts > {2} AND f._ts <= {3}",
                        DocumentDbRepository.DatabaseId, Enums.Events.ApplicationAuthenticationSuccess, refUnixTime,
                        currentUnixTime);

ERROR:

"message":"Syntax error, invalid numeric value token '4d5f'."

any help would be appreciated!

Upvotes: 2

Views: 2149

Answers (2)

anand kadu
anand kadu

Reputation: 76

I also faced similar issue while using Cosmos DB Java API. It got resolved using SqlQuerySpec APIs

Use DocumentClient.queryDocuments(String collectionLink, SqlQuerySpec querySpec,FeedOptions options)

@param1 and @param2 are placeholder in query string and will be replaced by id and user when we set to SqlParameter. When SqlParameterCollection and query are passed to SQLQuerySpec , it replace placeholder values from query string with corresponding value againt key userd in SqlParameterCollection.

//Create SQLQuerySpec instance as below


String query = "SELECT * FROM mycollections m WHERE w.id =@param1 and w.user 
=@param2";
SqlParameterCollection col = new SqlParameterCollection();
SqlParameter sqlParameter1 = new SqlParameter("@param1", id);
SqlParameter sqlParameter2 = new SqlParameter("@param1", user);
col.add(sqlParameter1);
col.add(sqlParameter2);
SQLQuerySpec sqlspec = new SQLQuerySpec(query,col);
FeedOptions options = new FeedOptions()
options.setEnableCrossPartitionKey(true);
List<Documents> results = documentClient.queryDocuments(collectionLink, 
sqlSpec,options).getQueryIterable().toList()

Upvotes: -1

Samer Boshra
Samer Boshra

Reputation: 919

If this is the replacement value of {0} in the FROM clause, then it has to conform to a valid identifier (i.e. starts with an alphabetic character or underscore). Anyways, you really don't need to specify the database Id here, any identifier will do since the collection is always the one you're connected to. In other words, you could write the query as 'SELECT ... FROM f WHERE ...)

Upvotes: 5

Related Questions