admin管理员组

文章数量:1401939

new to cosmoDB tried this and it worked fine

cosmos_db = cosmos_client.create_database_if_not_exists("Test_DB")
container = cosmos_db.create_container_if_not_exists("test_data", PartitionKey(path='/id', kind='Hash'))

container.create_item({"id": "1", "value": "foo"})
container.upsert_item({"id": "2", "value": "bar"})
container.upsert_item({"id": "3", "value": "HelloWorld"})

item = container.read_item("1", partition_key="1")
assert item["value"] == "foo"

queryText = "SELECT * FROM test_data d where d.id = '1'"
results = container.query_items(query=queryText,
                                enable_cross_partition_query=False,
                               )
items = [item for item in results]

works for both the query and the read_item. When I use

queryText = "SELECT * FROM test_data d where d.value = 'foo'"

it fails wild and with

Code: BadRequest
Message: Failed to parse token 'value' at position 36

is there a way to avoid the big stack trace and even better to query for foo ?

new to cosmoDB tried this and it worked fine

cosmos_db = cosmos_client.create_database_if_not_exists("Test_DB")
container = cosmos_db.create_container_if_not_exists("test_data", PartitionKey(path='/id', kind='Hash'))

container.create_item({"id": "1", "value": "foo"})
container.upsert_item({"id": "2", "value": "bar"})
container.upsert_item({"id": "3", "value": "HelloWorld"})

item = container.read_item("1", partition_key="1")
assert item["value"] == "foo"

queryText = "SELECT * FROM test_data d where d.id = '1'"
results = container.query_items(query=queryText,
                                enable_cross_partition_query=False,
                               )
items = [item for item in results]

works for both the query and the read_item. When I use

queryText = "SELECT * FROM test_data d where d.value = 'foo'"

it fails wild and with

Code: BadRequest
Message: Failed to parse token 'value' at position 36

is there a way to avoid the big stack trace and even better to query for foo ?

Share Improve this question asked Mar 24 at 18:47 user3732793user3732793 1,9807 gold badges29 silver badges57 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

value is a reserved keyword. Used in statements like SELECT VALUE...

You can either use a different property name or d["value"].

本文标签: pythonselect value does fail in cosmo dbStack Overflow