gpt4 book ai didi

python - Dynamodb 查询具有多个属性值

转载 作者:行者123 更新时间:2023-11-30 23:13:38 24 4
gpt4 key购买 nike

如何使用多个值进行查询?例如,last_name 为 ["Doggett","Scully","Mulder"] 的所有用户

使用 boto 的示例。

    Table.create('users', 
schema=[
HashKey('id') # defaults to STRING data_type
], throughput={
'read': 5,
'write': 15,
}, global_indexes=[
GlobalAllIndex('LastnameTimeIndex', parts=[
HashKey('last_name'),
RangeKey('creation_date', data_type=NUMBER),
],
throughput={
'read': 1,
'write': 1,
}),
],
connection=conn
)

类似于:

table = Table("users", connections=conn)
table.query_2(last_name__in=["Doggett","Scully","Mulder"], connection=conn)

最佳答案

目前,查询 API 不支持 IN 条件 KeyCondition 。正如 Max 所建议的,您需要进行单独的查询。您还可以并行进行查询以提高性能。

如果您想使用 IN,则需要进行扫描(或示例中的索引扫描)。

关于python - Dynamodb 查询具有多个属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29219015/

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