简体   繁体   English

如何使用 Python 在 dynamodb 中使用运算符

[英]how to use in operator in dynamodb using Python

How can we query on a table in DynamoDB with IN clause using Python?我们如何使用 Python 查询 DynamoDB 中带有 IN 子句的表?

I have users table, Here is schema[username is Partition key]:我有用户表,这是架构[用户名是分区键]:

{
    username:"ABC_15",
    password:"1234",
    company: "15",
     Id    :  ABC
}


I want to query like SQL:我想像 SQL 这样查询:

Select * from users where id in ('ABC','XYZ','FGH') Select * 来自 id 在 ('ABC','XYZ','FGH') 中的用户

and id is not a Partitionkey in table.并且 id 不是表中的 Partitionkey。

I am using below code, is there any other option avilable:我正在使用下面的代码,是否还有其他可用的选项:

dynamodb = boto3.resource('dynamodb', region_name='ap-southeast-2', endpoint_url="http://localhost:8000")
table = dynamodb.Table('users_setup')
users1 = "ABC,XYZ"
print(users1)
users = users1.split(',')

try:
    response = table.scan(
        
            FilterExpression=Attr('id').is_in(users) 
        
    )
except ClientError as e:
    print(e.response['Error']['Message'])
else:
    items = response['Items']
    print(items)
    print("Scan succeeded:")


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM