dynamoid icon indicating copy to clipboard operation
dynamoid copied to clipboard

A question about timestamp columns

Open elioncho opened this issue 2 years ago • 2 comments

Hi,

As you see in the image below, the native created_at column in the table has high precision, but the sort key (installation_execution_created_at) does not. This is leading to non-unique issues. Why is it that a DateTime such as '2021-05-31 16:36:20.461637' or '2022-05-12T00:22:33.144Z' are not stored with decimal places?

CleanShot 2022-05-11 at 20 08 23@2x

elioncho avatar May 12 '22 01:05 elioncho

Hi, could you please provide the Dynamoid version that is in use and the fields declaration in the Dynamoid model (I mean table/field DSL methods)?

andrykonchin avatar May 12 '22 10:05 andrykonchin

Hi @andrykonchin, thanks for the quick reply. The issue is that Rails ActiveRecord helpers for DateTime fields return an object with less precision, so a date like this '2022-05-12T00:22:33.144Z' is returned as '2022-05-12T00:22:33 UTC'.

The solution was to pass in the date with more precision using strftime, like this:

created_at.strftime("%F %H:%M:%S.%12N %Z")

Once I pass the date as above, it is saved in Dynamodb with decimal places.

elioncho avatar May 16 '22 16:05 elioncho