gpt4 book ai didi

python - 如何对 query_entities 使用过滤器

转载 作者:行者123 更新时间:2023-12-03 02:50:52 24 4
gpt4 key购买 nike

我想对 Azure 表存储的 query_entities 使用筛选器。

我尝试过使用这样的过滤器:表 = table_service.query_entities('MyTableName', filter = "RowKey eq 20")

#coding:utf-8
import os
import json
from azure import *
from azure.storage import *
from azure.storage.table import TableService, Entity

table_service = TableService(account_name='MyAccountName',
sas_token='MySASToken')
Table = table_service.query_entities('MyTableName', filter = "Country eq
USA")
print(Table.items)

我遇到了一个异常(exception):

azure.common.AzureHttpError: Bad Request {"odata.error":{"code":"InvalidInput","message":{"lang":"en-US","value":"A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Int32' for operator kind 'Equal'.\nRequestId:ef3858e7-5002-00d0-617f-0d374a000000\nTime:2019-05-18T13:45:23.6288160Z"}}}

我尝试更改为:

Table  = table_service.query_entities('MyTableName', filter = "Country eq 
USA")

但是我得到了 SyntaxError: 无效语法

最佳答案

试试这个过滤器:

Country eq 'USA'

基本上,您的属性的数据类型是String,因此该值需要用单引号引起来。

同样的事情也适用于您的 RowKey 查询:

RowKey eq '20'

您可以在这里找到更多示例:https://learn.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities#sample-query-expressions .

关于python - 如何对 query_entities 使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com