英文:
How dynamoDB queries work on DateTimeString
问题
我有一个 DynamoDB 表,其中的项目如下:
Ordered order_date created_at details
123 2023-05-10 10:04:05 Date#2023-05-10T00:00:00 {}
32132 2023-05-11 11:04:05 Date#2023-05-101T00:00:00 {}
orderId 是分区键(partition_key),order_date/created_at 是表的排序键(sort_key)。
根据 DynamoDB 文档的说明,DynamoDB 仅支持 ISO 格式的日期字符串进行日期时间查询。上述格式中的 order_date 不是 ISO 格式。
- 如果我在 order_date(排序键)上执行区间查询,DynamoDB 会如何行为?
- 如果我在 created_at(复合排序键)上执行区间查询,DynamoDB 会如何行为?
提前感谢。
英文:
I have a DynamoDB table which items are like
Ordered order_date created_at details
123 2023-05-10 10:04:05 Date#2023-05-10T00:00:00 {}
32132 2023-05-11 11:04:05 Date#2023-05-101T00:00:00 {}
orderId is partition_key and order_date/created_at is sort_key of table.
As mentioned in dynamoDB doc, dynamoDB support only ISO format date string for date Time queries. order_date in the above format is not ISO format.
- how will dynamoDB behave if i do between query on order_date (sort_key) here.
- how will dynamoDB behave if i do between query on created_at (compound sort_key) here.
Thanks in advance
答案1
得分: 1
DynamoDB 将日期存储为字符串值,因此最好将它们视为普通字符串。它按字典顺序排序字符串,只要您的比较在字典顺序上正确,它就会正常工作。
此外,一张表只能有一个排序键,不能有两个。如果想要在非键字段上进行排序,需要使用 FilterExpression。
英文:
DynamoDB stores dates as string values, so its best to think of them as just strings. It sorts strings lexicographically, so as long as your comparisons are lexicographically correct it will work.
Furthermore, you can only have 1 sort key on a table, not two. If you want to sort on a non-key field you need to use a FilterExpression
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论