Python - Retrieving max primary key value from DynamoDB using Boto3(Python - 使用 Boto3 从 DynamoDB 检索最大主键值)
问题描述
我只是想通过使用 Boto3 的查询/扫描来检索我的主键的最大值.我正在尝试完成此操作,因此我的程序可以简单地将我设置为等于最大ID"值的变量增加 1 以用于下一个表条目.
I'm simply trying to retrieve the max value of my primary keys with a query/scan using Boto3. I'm trying to accomplish this so my program can simply increment a variable I'll set equal to the max "ID" value by 1 for the next table entry.
DynamoDB 表的屏幕截图
response = table.scan(
FilterExpression=Attr('ID'). #Here is where I'd assume a condition
) #is placed to find the highest value but
#the Boto3 doc doesn't seem to have a
#method like 'max()' or something...
四处搜索我发现如何使用原始的boto"来做到这一点,所以我确信有一种方法可以使用它的新版本boto3",但我还没有找到任何东西.
Searching around I found how to do this using the original 'boto' so I'm sure there is a way using its newer version 'boto3' but I haven't found anything yet.
任何帮助/指导将不胜感激!谢谢!
Any help/guidance would be greatly appreciated! Thanks!
Boto3 文档:http://boto3.阅读thedocs.io/en/latest/guide/dynamodb.html#querying-and-scanning
推荐答案
我遇到了同样的问题,找不到优雅的解决方案.但是,如果您的主键只是整数,您可以执行以下操作来查找最大键:
I am suffering from the same issue and can't find an elegant solution. However if your primary keys are just integers you can do something like this to find the max key:
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
max_key = table.item_count
这篇关于Python - 使用 Boto3 从 DynamoDB 检索最大主键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python - 使用 Boto3 从 DynamoDB 检索最大主键值
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
