ANSantana
ANSantana

Reputation: 33

How Scan Values with colon ":" from a Dynamodb Table?

I am facing a similar problem, using boto3 the query does not work, while it works on console.

First I tried this scan without success:

text = 'city:barcelona'
filter_expr = Attr('timestamp').between('2020-04-01', '2020-04-27')
filter_expr = filter_expr & Attr('text').eq(text)
table.scan(FilterExpression = filter_expr, Limit = 1000)

Then, I notice that for a text variable that does not contain ":", the scan works. So, I tried this second scan using ExpressionAttributeNames and ExpressionAttributeValues

table.scan(
            FilterExpression = "#n0 between :v0 AND :v1 AND #n1 = :v2",
            ExpressionAttributeNames = {'#n0': 'timestamp', '#n1': 'text'},
            ExpressionAttributeValues = {
                ':v0': '2020-04-01', 
                ':v1': '2020-04-27', 
                ':v2': {"S": text}},
            Limit = 1000
            )

Failed again.

By the end, if I change in the first example:

I can get the records. IMO, it is clear that the problem is the ":"

Is there another way to search by texts with ":" character?

Upvotes: 1

Views: 940

Answers (1)

jarmod
jarmod

Reputation: 78673

[writing an answer so that we can close out the question]

I ran both examples and they worked correctly for me. I configured text and timestamp as string fields. Check you have an up to date boto3 library.

Note: I changed ':v2': {"S": text} to ':v2': text because you're using resource level scan and you don't need to supply the low-level attribute type (it's only required for client level scan).

Upvotes: 1

Related Questions