[Python] select value does fail in cosmo db

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    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 ?

    Continue reading...

Compartilhe esta Página