Using a ProjectionExpression with reserved words with Boto3 in DynamoDB(在 DynamoDB 中使用带有保留字的 ProjectionExpression 和 Boto3)
问题描述
我正在使用 boto3 从我的 DynamoDB 数据库中选择数据
I'm selecting data from my DynamoDB database using boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
response = table.scan(ProjectionExpression='Id,Name')['Items']
工作正常.现在我还想检索一个(不幸的是)用保留字命名的属性 - 比如说 CONNECTION
.
Works fine. Now I also want to retrieve an attribute that is (unfortunately) named with a reserved word - let's say CONNECTION
.
response = table.scan(ProjectionExpression='Id,Name,Connection')['Items']
我收到类似
调用 Scan 时发生错误 (ValidationException)操作:无效的 ProjectionExpression:属性名称是保留的关键词;保留关键字:连接
An error occurred (ValidationException) when calling the Scan operation: Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: Connection
我知道在使用过滤器或查询时有一种别名技术,但是对于来自 boto3 的简单投影是否存在这种技术?
I know there's an aliasing technique if using filters or queries, but does this exist for simple projections from boto3?
推荐答案
原来这和直接调用DynamoDB API一样很容易解决.
Turns out that this is easily solved the same as when calling the DynamoDB API directly.
我们应该为任何保留字使用别名,然后使用 ExpressionAttributeName 参数/属性.
We should use an alias for any reserved word, and then provide a mapping from the alias back to the 'true' name with the ExpressionAttributeName parameter/property.
response = table.scan(ProjectionExpression = 'Id, Name, #c',
ExpressionAttributeNames = {'#c': 'Connection'})['Items']
这篇关于在 DynamoDB 中使用带有保留字的 ProjectionExpression 和 Boto3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 DynamoDB 中使用带有保留字的 ProjectionExpression 和 Boto3


- 计算测试数量的Python单元测试 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01