Timestamp with nanoseconds for sorting (insertion order)

There is no data type timestamp. timestamp is stored as ISO-8601 standard string format. Once in this format it is string comparable. Also N1QL has convenient string functions https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/datefun.html.

The convenient functions uses milliseconds due to limit of number in JSON. int64 can only fit certain range any number 2**53 will stored as float64 and looses precision. https://golang.org/pkg/time/#Time.UnixNano

If you are only looking for sort store AS ISO-8601 format with fraction second contains upto 9 digits with leading 0 then reset of things in N1QL should work seamlessly. When use N1QL date functions it should truncate to milliseconds(i have not tested but you can do quick test).
Example: “2019-03-06T06:18:51.000000491-08:00”

1 Like