简体   繁体   English

如何在使用 python 的同一语句中使用 AND 和 OR 查询/扫描 DynamoDB 中的表?

[英]How to query/scan a table in DynamoDB using AND and OR in the same statement using python?

I want to query a table on DynamoDB and using python.我想在 DynamoDB 上查询一个表并使用 python。 The thing with this query is that I want to use an AND and OR condition in the same query.这个查询的问题是我想在同一个查询中使用 AND 和 OR 条件。 I want the query to retrieve values from one column when the value is B or C.当值为 B 或 C 时,我希望查询从一列中检索值。

I have the following table:我有下表:

domain          validation_A        validation_B        validation_C
---------       -----------------   ---------------     ---------------
drene.com       pass                pass                pass
drene.com       pass                true                pass
drene.com       fail                pass                pass

In regular SQL expression I will use:在正则 SQL 表达式中,我将使用:

Select * 
from 
    ValidationTable 
where 
    domain = 'drene.com' and 
    validation_A = 'pass' and 
    (validation_B = 'pass' or validation_B = 'true') 

I do not know how to do this in DynamoDB / Pythom我不知道如何在 DynamoDB/Pythom 中做到这一点

I tried the following:我尝试了以下方法:

response = table.scan(
                 IndexName="Date-index",
                 FilterExpression=Key('domain').eq('drene.com') & Attr('validation_A').eq('pass') & (Attr('validation_B').eq('pass') || Attr('validation_B').eq('true'))

) )

But it is not working但它不起作用

I need the query bring me the first 2 rows.我需要查询给我带来前 2 行。

Use |使用| instead of ||而不是||

response = table.scan(
                 IndexName="Date-index",
                 FilterExpression=Key('domain').eq('drene.com') & Attr('validation_A').eq('pass') & (Attr('validation_B').eq('pass') | Attr('validation_B').eq('true'))

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

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