DynamoDB中的时间戳应该使用哪种数据类型? [英] What data type should be use for timestamp in DynamoDB?

查看:382
本文介绍了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.


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

  1. 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中的时间戳应该使用哪种数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆