使用查询(Python boto3)从Dynamo DB表中获取所有记录
我在Dynamo DB中有一张桌子,有200万张记录。该表有日期(yyyy-mm-dd
)作为分区键,并且我将作为排序键。当前,我们正在使用boto3.client.dynamodb.query
基于keyconditionexpression
获取数据,其中x
是日期。我想根据一年来查询记录吗? KeyConditionExpression
和表达式属性值
是什么?
dynamo db中的示例行:
{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}
date
是分区键,account_id
是零为键。我想通过2022年查询所有记录。
I have a table in Dynamo Db with 2 million records. The table has date (yyyy-mm-dd
) as partition key and account I'd as sort key. Currently, we are using boto3.client.dynamodb.query
to fetch the data based on KeyConditionExpression
where X
is date. I want to query the records based on just year? What should KeyConditionExpression
and Expression Attribute Values
be?
Sample row in Dynamo Db :
{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}
Here date
is partition key and account_id
is sort key. I want to query all the records with year 2022.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询只能在单个分区密钥上操作。如果要运行此查询,则需要将GSI与本年度作为分区密钥添加。这具有额外的写入和存储成本。如果您不需要经常运行此查询,则仅扫描表并在应用程序层中过滤可能会便宜。如果您有200万个记录,并且每个记录为500个字节,则扫描成本小于$ 0.02
A query can only operate on a single partition key. If you want to run this query, you need to add a GSI with the year as the partition key. This has additional write and storage costs. If you don’t need to run this query very often, it may be cheaper to just scan the table and filter in the application layer. If you have 2 million records and each record is 500 bytes, the cost of a scan is less than $0.02