简体   繁体   中英

Filter Dynamo DB rows

I want to filter all dynamo db rows where 2 columns have same value

 table = client.Table('XXX')
   response = table.query(
   KeyConditionExpression=Key('column1').eq(KeyConditionExpression=Key('column2'))
 )

this is wrong as we can't pass KeyConditionExpression inside eq statement. I don't want to scan through all the rows and filter the rows.

Scanned through multipole resources and answers but every resources talks about the multiple column checking with some value not multiple condition involving columns

Is there anyway we can achieve this?

Yes, this is possible.

If you want query over all records you need to use scan , if you want to query only records with one specific partition key you can use query .

For both you can use a FilterExpression , which will filter the records after retrieving them from the database, but before returning them to the user (so beware, using a scan with this will read all your records).

A scan from the CLI could look like this:

aws dynamodb scan \
    --table-name your-table \
    --filter-expression "#i = #j" \
    --expression-attribute-names '{"#i": "column1", "#j": "column2"}'

Create a Global Secondary Index with a partition key of 'Column1Value#Column2Value'

Then it's simply a matter of querying the GSI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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