DynamoDB中的时间戳应该使用哪种数据类型?

编程入门 行业动态 更新时间:2024-10-26 22:27:25
本文介绍了DynamoDB中的时间戳应该使用哪种数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是DynamoDB的新手。我希望创建一个使用DeviceID作为哈希键,使用Timestamp作为我的范围键和一些数据的表。

I am new to DynamoDB. I wish to create a table which using DeviceID as the hash key, Timestamp as my range key and some data.

{ DeviceID: 123, Timestamp: "2016-11-11T17:21:07.5272333Z", X: 12, Y: 35 }

在SQL中,我们可以将datetime类型用作时间戳,但在DynamoDB中则没有。

In SQL, we can use datetime type for Timestamp, but in DynamoDB there is none.

  • 我应该使用哪种数据类型?串?数字吗?

  • What data type should I use? String? Number?

    对于所选数据类型,应使用哪种时间戳格式我写?是ISO格式(例如:2016-11-11T17:21:07.5272333Z)或时期(例如:1478943038816)?

    For the chosen data type, what kind of timestamp format should I write in? ISO format (e.g: 2016-11-11T17:21:07.5272333Z) or epoch time (e.g: 1478943038816)?

    我需要在表格中搜索一段时间,例如:2015年1月1日上午10:00:00,直到2016年12月31日11 :00:00pm

    I need to search through the table through a range of time, e.g: 1/1/2015 10:00:00am until 31/12/2016 11:00:00pm

    推荐答案

    字符串数据类型

    The String data type should be used for Date or Timestamp.

    您可以使用String数据类型表示日期或时间戳。 做到这一点的一种方法是使用ISO 8601字符串,如这些示例所示:

    You can use the String data type to represent a date or a timestamp. One way to do this is by using ISO 8601 strings, as shown in these examples:

    2016-02-15

    2016-02-15

    2015-12-21T17:42:34Z

    2015-12-21T17:42:34Z

    20150311T122706Z

    20150311T122706Z

    DynamoDB数据日期或时间戳记的类型

    是,当日期存储为字符串时,支持范围查询。 BETWEEN 可以在FilterExpresssion上使用。我已经使用下面的过滤器表达式获得了结果中的项目。

    Yes, the Range queries are supported when the date is stored as String. The BETWEEN can be used on FilterExpresssion. I have got the items in the result using the below filter expressions.

    FilterExpression没时间:-

    FilterExpression : 'createdate between :val1 and :val2', ExpressionAttributeValues : { ':hkey' : year_val, ':rkey' : title, ":val1" : "2010-01-01", ":val2" : "2010-12-31" }

    FilterExpression with time:-

    FilterExpression : 'createdate between :val1 and :val2', ExpressionAttributeValues : { ':hkey' : year_val, ':rkey' : title, ":val1" : "2010-01-01T00:00:00", ":val2" : "2010-12-31T00:00:00" }

    数据库值:-

    格式1-带有时区:

    {"Item":{"createdate":{"S":"2010-12-21T17:42:34+00:00"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}

    格式2-没有时区:-

    {"Item":{"createdate":{"S":"2010-12-21T17:42:34Z"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}
  • 更多推荐

    DynamoDB中的时间戳应该使用哪种数据类型?

    本文发布于:2023-10-19 07:23:50,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1506787.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:哪种   数据类型   时间   DynamoDB

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!