python - 如何对 query_entities 使用过滤器

标签 python azure

我想对 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/

相关文章:

python - 获取任意文件类型的缩略图

python - XMPP 订阅节 Google Talk

python - 设置日志记录级别

c# - WCF服务如何获取查询参数?

azure - SQL Azure 中的备份非常慢

python - 如何在 Pandas 中汇总一列

python - 如何在 python 中移动 2-5 字节长的字节对象中的位?

azure - 如何使用 Terraform 为每个开发人员创建 Azure 服务总线命名空间实例并将其保存在状态中

azure - Azure 数据工厂数据流中动态模式的“存在条件”

visual-studio - 如何拥有更多多个 ServiceConfiguration 文件而不仅仅是 ".local"和 ".cloud"?