# Support for nanoseconds in timestamps

**URL:** <https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893>\
**Category:** Feedback\
**Created:** [April 6, 2021, 7:00pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893 "2021-04-06T19:00:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prerak](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prerak](https://www.singlestore.com/forum/u/prerak)\
**Post date:** [April 6, 2021, 7:00pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/1 "2021-04-06T19:00:02Z")

</div>

**Describe the problem you’re experiencing?**  
We would like to be able to store timestamps with nanoseconds. The finance industry, specifically US Equities, has been required by regulation to capture and report timestamps in nanoseconds for a while now. See this: [Regulatory Notice 20-41 | FINRA.org](https://www.finra.org/rules-guidance/notices/20-41). Singlestore doesn’t support `TIMESTAMP(9)`, which causes us to store data using multiple fields, a `TIMESTAMP(6)` for human readability, and another `bigint` field which contains nanoseconds since epoch. We use columnstore tables that are sorted by this nanosecond field, but we often query using the `TIMESTAMP(6)` column because it is easier to interact with. This is not only wasteful in terms of space but not great for performance.

We have tried using a calculated field for this purpose (a calculated timestamp field based on the nanoseconds-since-epoch field), but were disappointed to find that calculated fields cannot have a `TIMESTAMP` datatype.

**What is your ideal solution? What are you looking for?**  
Be able to use `TIMESTAMP(9)` or at least a calculated field of type `TIMESTAMP(6)`

**What version(s) of MemSQL or related tools is this affecting?**  
All

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [April 9, 2021, 9:57pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/2 "2021-04-09T21:57:01Z")

</div>

Hi @prerak, thanks for your well-thought-out feature request. We are already tracking this one. I added your details to it. I assume you are also okay with DATETIME(9) even if we don’t do TIMESTAMP(9), is that right? Timestamp runs out in 2038 right now, so it is not recommended for new development. Of course, a TIMESTAMP(9) type could cover a longer span, perhaps.

---

<div class="post-metadata">

**Author:** ![prerak](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prerak](https://www.singlestore.com/forum/u/prerak)\
**Post date:** [April 9, 2021, 10:28pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/3 "2021-04-09T22:28:57Z")

</div>

Thank you. Yes, datetime(9) is equally good. In our systems, we use a 64-bit integer to represent nanos since epoch, which will work for a couple of hundred years more.

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [April 9, 2021, 11:51pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/4 "2021-04-09T23:51:57Z")

</div>

That’s good to know. What do you use for your epoch?

---

<div class="post-metadata">

**Author:** ![prerak](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prerak](https://www.singlestore.com/forum/u/prerak)\
**Post date:** [April 10, 2021, 1:31am UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/5 "2021-04-10T01:31:22Z")

</div>

Just the unix epoch, it’s much easier to interoperate or exchange data with other systems / languages that way (divide by a thousand, million, or billion and can turn that into a timestamp usable by most any language - Python, JavaScript, or even shell scripts)

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [April 12, 2021, 7:53pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/6 "2021-04-12T19:53:23Z")

</div>

Thanks, @prerak. I can see the benefit of that.

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [November 22, 2023, 6:08pm UTC](https://www.singlestore.com/forum/t/support-for-nanoseconds-in-timestamps/2893/7 "2023-11-22T18:08:16Z")

</div>

Support for nanosecond-precision timestamps can be done with a Wasm extension. We’ve made an open-source sample, written in Rust, available here:

> **[GitHub - singlestore-labs/timestamp9](https://github.com/singlestore-labs/timestamp9)**
>
> Contribute to singlestore-labs/timestamp9 development by creating an account on GitHub.

It works by storing the number of nanoseconds since the epoch in a 64-bit integer (bigint). The extension has functions to convert from string to that format and from that format back to string.

For sorting and comparisons, a nice thing about this approach is that you can just do those on the raw (bigint) data.
