# Generate CSV-file from Influx database

**URL:** <https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605>\
**Category:** General\
**Created:** [23 October 2021 08:36 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605 "2021-10-23T08:36:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [23 October 2021 08:36 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/1 "2021-10-23T08:36:15Z")

</div>

I've been struggling with the following for a while now.

A growing Influx DB "luchtdruk" contains the fields _luchtdruk_ and _tijd_ (see picture) over the last weeks. I would like to generate a comma separated CSV file from this database with only two columns namely _tijd_ and _luchtdruk_ and then only the last 24 hours.

Can someone help me with this?

![DB](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76dc5fc7737d9d7972c80aa7a30b81c76278cd92.png)

---

<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:** [23 October 2021 09:08 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/2 "2021-10-23T09:08:59Z")

</div>

The influx docs are not bad in this area, with many examples. Start with something like  
`select "luchtdruk","tijd" from .....`  
I hope that `tijd` is not another representation of the time field, if it is then it should not really be there, derive it from the time value when you need it.

[https://docs.influxdata.com/influxdb/v1.8/query\_language/explore-data/#the-basic-select-statement](https://docs.influxdata.com/influxdb/v1.8/query_language/explore-data/#the-basic-select-statement)

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [23 October 2021 10:21 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/3 "2021-10-23T10:21:22Z")

</div>

Thanks. Selecting data from Influx is not the problem, I know how to do that. My problem is how to select from Influx within Node Red. Besides the Influx database is what it is, I can't change it.

The reason there is a field _tijd_ is because an Influx timestamp is stored in nanoseconds while a javascript timestamp is stored in milliseconds. This causes problems when generating a CSV-file so the extra field _tijd_ is there.

---

<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:** [23 October 2021 10:50 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/4 "2021-10-23T10:50:36Z")

</div>

> [@HaVi](#):
>
> This causes problems when generating a CSV-file so the extra field _tijd_ is there.

I had not noticed any difficulty dividing by 1 million in node-red.

> [@HaVi](#):
>
> My problem is how to select from Influx within Node Red.

That is the easy bit, which is why I assumed that the sql query was the problem. [node-red-contrib-influxdb (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-influxdb)

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [23 October 2021 11:07 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/5 "2021-10-23T11:07:21Z")

</div>

Thanks Colin. I believe without a doubt you are right about the _tijd_ field but that is not the problem. The point is that I want to convert the measurements of the last 24 hours to a CSV file. In the flow below I select the last 20 measurements and that works fine but that should be the last 24 hours.

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/1966eb4a93bdd947cd19103f07a6b0ea8ea85ed4.png)

---

<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:** [23 October 2021 12:11 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/6 "2021-10-23T12:11:22Z")

</div>

So it _is_ the SELECT statement that you need help with. You need to use a WHERE clause to select for the the last 24 hours. Have a look in the docs I linked to.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [23 October 2021 12:34 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/7 "2021-10-23T12:34:34Z")

</div>

Now it's clear to me that the node uses the same commands as Influx DB. I didn't know that and I didn't understand you. Now solved by using the query below and it works fine 🙂

```auto
SELECT "tijd","luchtdruk" FROM "luchtdruk" WHERE time > now() - 24h

```

---

<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:** [23 October 2021 14:14 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/8 "2021-10-23T14:14:39Z")

</div>

All the node does is to pass the statement on to Influx and give you the results.

---

<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:** [22 December 2021 14:14 UTC](https://discourse.nodered.org/t/generate-csv-file-from-influx-database/52605/9 "2021-12-22T14:14:52Z")

</div>

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