dynamoid
dynamoid copied to clipboard
A question about timestamp columns
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](https://user-images.githubusercontent.com/29183/167972048-efe3e351-902b-46fd-8067-cd551db27232.png)
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)?
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.