简体   繁体   中英

How to query DynamoDB using python for date range which is stored as string?

This is a tricky one for me, so I thought I would check here.

I have a DynamoDB table where timestamps are stored in following format as string datatype:

'timestamp': '2022-06-25 22:44:10.536370'

Now I need to be able to query this table for data with time ranges. And the time range would be something like this:

'from':'2021-02-17 13:00:00' 
'to': '2021-02-17 14:00:00’

How I can write this as a query condition in python? I am a frontend developer and only know basic SQL so I am not sure how to create this query...

Any help is greatly appreciated!

The simple way to query DynamoDB is using the PartiQL interface, that you can read more about it here: https://aws.amazon.com/blogs/database/build-faster-with-amazon-dynamodb-and-partiql-sql-compatible-operations/

For your query on the dates you can use something like:

SELECT * FROM my_table WHERE timestamp BETWEEN '2021-02-17 13:00:00' AND '2021-02-17 14:00:00'

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