Reputation: 19
We have a DDB with a column : Timestamp (string)
Essentially we need to query data between a range of the Timestamp
column.
What is the best way to do this?
I tried creating a GSI in my test environment using the Timestamp
column but quickly realized that I will not be able to query a range of this column.
Edit: What I found as the best way to do this so far:
Update
Timestamp
column instead, so I am able to query on a range of the timestampDo let me know if you know a better way to do this. Thanks.
Upvotes: 0
Views: 407
Reputation: 3677
Your approach is good. DynamoDB supports dates and you can do your query using "BETWEEN".
A much better, but situational, approach is to include the time range in the partition key. If your time ranges are always of the same size for example 1 day you can do something like
PK
EVENT_TIME_RANGE#(start <-> end)
Then retrieve all of the entires in this time range with a very effective PK lookup query.
If you can't do that but need to optimize for time range lookups you can copy the data into this "home made" time range index.
Upvotes: 1