DynamoDB 查询如何在 DateTimeString 上工作

huangapple go评论64阅读模式
英文:

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 格式。

  1. 如果我在 order_date(排序键)上执行区间查询,DynamoDB 会如何行为?
  2. 如果我在 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.

  1. how will dynamoDB behave if i do between query on order_date (sort_key) here.
  2. 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

huangapple
  • 本文由 发表于 2023年6月22日 02:18:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定