# Nanosecond Precision with InfluxDB

**URL:** https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278
**Category:** General
**Tags:** database
**Created:** [18 July 2022 16:30 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278 "2022-07-18T16:30:58Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![fludki](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@fludki](https://discourse.nodered.org/u/fludki)
#### Post date: [18 July 2022 16:30 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/1 "2022-07-18T16:30:58Z")

</div>

I am struggling with ns resolution timestamps from an influxDB (node-red-contrib-influxdb). The data is high-resolution acceleration data with a sampling frequency of several kHz. To make exact timestamps I would need ns resolution. Saving the data to the database works and in the DB it is stored with correct precision (see picture). After the query, the last digits are replaced by zeros. Any guesses what I can do in this particular case?

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d374f05e5d17fb76c3c2ad5df9fa323f30318b0.png)

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cdc997c0d6a34c08a5cf7eda8ac9bceea4a5afa0.png)

Thanks in advance!

---

<div class="post-metadata">

### Author: ![fludki](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@fludki](https://discourse.nodered.org/u/fludki)
#### Post date: [18 July 2022 16:31 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/2 "2022-07-18T16:31:47Z")

</div>

How it is stored in the DB:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e036151b3f28fe23b0edcc22446558b8780ba20.png)

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [18 July 2022 17:16 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/3 "2022-07-18T17:16:19Z")

</div>

I'm still somewhat new (so I could be way off), but could you be running into an issue with [Number.MAX\_SAFE\_INTEGER - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)

Your `msg.payload.results[0].series[0].values[7][0]` is set to:

`1658150533469000000`

but the max is

`9007199254740991`

---

<div class="post-metadata">

### Author: ![fludki](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@fludki](https://discourse.nodered.org/u/fludki)
#### Post date: [18 July 2022 19:50 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/4 "2022-07-18T19:50:43Z")

</div>

I think you are right! Thanks a lot! Unfortunately I cant really change that. I found the part in the influx node-code:

```auto
                if (rawOutput) {
                    var queryPromise = client.queryRaw(query, queryOptions);
                } else {
                    var queryPromise = client.query(query, queryOptions);
                }

                queryPromise.then(function (results) {
                    msg.payload = results;
                    send(msg);
                    done();

```

I think I need to change the type of results to string or BigInt. Unfortunately this is an object. Any idea how to solve that?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 July 2022 20:06 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/5 "2022-07-18T20:06:28Z")

</div>

What are you going to do with the data once you get it into node-red?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 July 2022 20:12 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/6 "2022-07-18T20:12:51Z")

</div>

Also what do you see if you select Raw Output in the Influx In node?

---

<div class="post-metadata">

### Author: ![fludki](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@fludki](https://discourse.nodered.org/u/fludki)
#### Post date: [19 July 2022 05:59 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/7 "2022-07-19T05:59:38Z")

</div>

I get the data via MQTT and want to store it in a database first. Than you should be able to retrieve the data from the DB via dashboard and make a csv export.  
The picture in the first post shows the raw output. Below is the formatet output. Then it also formats the timestamp another way:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/458b8ce2c38137429a254f7953e21b2fe4933300.png)

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [19 July 2022 06:24 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/8 "2022-07-19T06:24:36Z")

</div>

If the influxdb node is getting in the way, don't forget that you can submit data to InfluxDB directly via its REST API. The line protocol is text rather than anything else so you can submit data to ns precision that way.

[InfluxDB line protocol tutorial | InfluxDB OSS 1.8 Documentation (influxdata.com)](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 July 2022 08:31 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/9 "2022-07-19T08:31:28Z")

</div>

> [@fludki](#):
>
> I get the data via MQTT and want to store it in a database first

Why are you getting it out of influx and then storing it in a database? It is already in a database (influx).

If you do need to store it in another db then will that db support those large numbers?

What are you going to do with the csv export?

As @TotallyInformation says, if you need to fetch the full precision timestamp you should be able to do it directly rather than using the influxdb node.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [2 August 2022 08:31 UTC](https://discourse.nodered.org/t/nanosecond-precision-with-influxdb/65278/10 "2022-08-02T08:31:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
