# Change Query from 1.8 to 2.0 Db influx

**URL:** <https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820>\
**Category:** General\
**Created:** [27 February 2023 16:23 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820 "2023-02-27T16:23:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [27 February 2023 16:23 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/1 "2023-02-27T16:23:48Z")

</div>

I want to change this flow and it is currently running on db1.8. but I want to use it with db2.0. The queries have changed.  
Can someone help me to create the right query?

```auto
[
    {
        "id": "7e76473157e64de4",
        "type": "influxdb in",
        "z": "22bb2ce990740b9b",
        "influxdb": "d49556922db36022",
        "name": "Abfrage",
        "query": "select * from \"KSEM\".\"KSEM2\" order by time desc Limit 1",
        "rawOutput": false,
        "precision": "s",
        "retentionPolicy": "",
        "org": "smarthome",
        "x": 320,
        "y": 1080,
        "wires": [
            [
                "5df5518c97863b87"
            ]
        ]
    },
    {
        "id": "ae39b4755d370594",
        "type": "inject",
        "z": "22bb2ce990740b9b",
        "name": "jede Minute",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 110,
        "y": 1080,
        "wires": [
            [
                "7e76473157e64de4"
            ]
        ]
    },
    {
        "id": "5df5518c97863b87",
        "type": "function",
        "z": "22bb2ce990740b9b",
        "name": "Influx",
        "func": "let Bez_M = msg.payload[0].Bezug;\nlet Ein_M = msg.payload[0].Einsp;\nlet Bez_T = msg.payload[1].Bezug;\nlet Ein_T = msg.payload[1].Einsp;\nmsg.payload = {Bez_M,Ein_M,Bez_T,Ein_T};\nmsg.topic = \"täglich & monatlich\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 1080,
        "wires": [
            [
                "6eed8a16b4174014"
            ]
        ]
    },
    {
        "id": "96f3e127a909ad43",
        "type": "join",
        "z": "22bb2ce990740b9b",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 470,
        "y": 1120,
        "wires": [
            [
                "6eed8a16b4174014"
            ]
        ]
    },
    {
        "id": "6eed8a16b4174014",
        "type": "join",
        "z": "22bb2ce990740b9b",
        "name": "",
        "mode": "custom",
        "build": "merged",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "6",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 690,
        "y": 1080,
        "wires": [
            [
                "096d0b59bafc40bb"
            ]
        ]
    },
    {
        "id": "a2805ed26f8df196",
        "type": "cronplus",
        "z": "22bb2ce990740b9b",
        "name": "jede Minute",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "Bezug Zähler",
                "topic": "Bez",
                "payloadType": "flow",
                "payload": "Bezug",
                "expressionType": "cron",
                "expression": "0 * * * * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            },
            {
                "name": "Einspeisung Zähler",
                "topic": "Ein",
                "payloadType": "flow",
                "payload": "Einsp",
                "expressionType": "cron",
                "expression": "0 * * * * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 110,
        "y": 1120,
        "wires": [
            [
                "96f3e127a909ad43"
            ]
        ]
    },
    {
        "id": "096d0b59bafc40bb",
        "type": "function",
        "z": "22bb2ce990740b9b",
        "name": "Werte",
        "func": "let Bez_T = msg.payload.Bez - msg.payload.Bez_T;\nlet Bez_M = msg.payload.Bez - msg.payload.Bez_M;\nlet Ein_T = msg.payload.Ein - msg.payload.Ein_T;\nlet Ein_M = msg.payload.Ein - msg.payload.Ein_M;\nmsg.payload = {Bez_M,Bez_T,Ein_M,Ein_T};\nObject.entries(msg.payload).forEach((v) =>{\n msg.payload[v[0]] = Math.round(v[1]*100)/100;\n})\nmsg.topic = \"Auswertung\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 1080,
        "wires": [
            [
                "58554023b0d4e2fb",
                "f08d22bd27e93e41",
                "1f5be3028323fe0b",
                "01e3cee029bfe671"
            ]
        ]
    },
    {
        "id": "58554023b0d4e2fb",
        "type": "ui_text",
        "z": "22bb2ce990740b9b",
        "group": "cab6742689765c7e",
        "order": 2,
        "width": 0,
        "height": 0,
        "name": "Einspeisung heute",
        "label": "<b><font color=orange> Einspeisung",
        "format": "{{msg.payload.Ein_T}} kWh",
        "layout": "row-spread",
        "className": "",
        "x": 1010,
        "y": 1060,
        "wires": []
    },
    {
        "id": "1f5be3028323fe0b",
        "type": "ui_text",
        "z": "22bb2ce990740b9b",
        "group": "e95a7cdc52bfdb3e",
        "order": 2,
        "width": 0,
        "height": 0,
        "name": "Einspeisung Monat",
        "label": "<b><font color=orange> Einspeisung",
        "format": "{{msg.payload.Ein_M}} kWh",
        "layout": "row-spread",
        "className": "",
        "x": 1010,
        "y": 1100,
        "wires": []
    },
    {
        "id": "f08d22bd27e93e41",
        "type": "ui_text",
        "z": "22bb2ce990740b9b",
        "group": "cab6742689765c7e",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "Bezug heute",
        "label": "<b><font color=red> Bezug",
        "format": "{{msg.payload.Bez_T}} kWh",
        "layout": "row-spread",
        "className": "",
        "x": 990,
        "y": 1140,
        "wires": []
    },
    {
        "id": "01e3cee029bfe671",
        "type": "ui_text",
        "z": "22bb2ce990740b9b",
        "group": "e95a7cdc52bfdb3e",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "Bezug Monat",
        "label": "<b><font color=red> Bezug",
        "format": "{{msg.payload.Bez_M}} kWh",
        "layout": "row-spread",
        "className": "",
        "x": 990,
        "y": 1180,
        "wires": []
    },
    {
        "id": "d49556922db36022",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "db",
        "name": "InfluxDB",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://192.168.178.16:8086",
        "rejectUnauthorized": false
    },
    {
        "id": "cab6742689765c7e",
        "type": "ui_group",
        "name": "Heute",
        "tab": "64033f10e63bd8ab",
        "order": 3,
        "disp": true,
        "width": "5",
        "collapse": false,
        "className": ""
    },
    {
        "id": "e95a7cdc52bfdb3e",
        "type": "ui_group",
        "name": "Monat",
        "tab": "64033f10e63bd8ab",
        "order": 4,
        "disp": true,
        "width": "5",
        "collapse": false,
        "className": ""
    },
    {
        "id": "64033f10e63bd8ab",
        "type": "ui_tab",
        "name": "Tageswerte",
        "icon": "trending_up",
        "order": 5,
        "disabled": false,
        "hidden": false
    }
]

```

---

<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:** [27 February 2023 16:40 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/2 "2023-02-27T16:40:16Z")

</div>

Do you mean you want to know what query you need to run (which is nothing to do with node-red)? If so then we don't need a flow, just tell us what the query is for 1.8.

---

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [2 March 2023 17:25 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/3 "2023-03-02T17:25:32Z")

</div>

select \* from "KSEM"."KSEM2" order by time desc Limit 1 = 1.8 Influx DB

what should the query be for 2.0 influxdb?

---

<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:** [3 March 2023 13:50 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/4 "2023-03-03T13:50:41Z")

</div>

Which part of the query don't you know how to do?  
If you don't know anything about how to do it then start with [Get started with Flux | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/get-started/)

---

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [8 March 2023 17:03 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/5 "2023-03-08T17:03:08Z")

</div>

Unfortunately I didn't understand that.

Would like feed today, feed month,

KSM tag

KSM2 month

---

<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:** [8 March 2023 17:23 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/6 "2023-03-08T17:23:00Z")

</div>

Perhaps you would be better sticking with version 1.8 then.

---

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [9 March 2023 17:45 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/7 "2023-03-09T17:45:58Z")

</div>

```auto
from(bucket: "db")
  |> range(start: -1d)
  |> filter(fn: (r) => r._measurement == "KSEM" and r._field == "Bezug")
  |> filter(fn: (r) => hourSelection(r._time))
  |> last()
  |> map(fn: (r) => ({value: r._value}))

hourSelection = (t) => hour(t) >= 0 and hour(t) <= 23

```

```auto
 compilation failed: error @4:24-4:46: expected comma in property list, got DOT error @4:39-4:45: unexpected token for property key: DOT (.)

```

---

<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:** [9 March 2023 21:02 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/8 "2023-03-09T21:02:03Z")

</div>

Which line is it that is failing? I don't know how to interpret the error message. You can find out by building the query up a bit at a time.

If it is the hourSelection bit, then `hourSelection()` is a built in function, so you can do things like  
` |> hourSelection( start: 8, stop: 19)`  
if that is what you are trying to achieve. So you don't need to provide your own version.

> **[hourSelection() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/hourselection/)**
>
> hourSelection() filters rows by time values in a specified hour range.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [9 March 2023 22:07 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/9 "2023-03-09T22:07:15Z")

</div>

LOL thats my flow 👌  
I use influx 1.6.x

---

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [9 March 2023 22:52 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/10 "2023-03-09T22:52:11Z")

</div>

Power values ​​from the Pv from the last day 0-24 hours, how much power was generated last day.

---

<div class="post-metadata">

**Author:** ![Shwowak](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Shwowak](https://discourse.nodered.org/u/Shwowak)\
**Post date:** [9 March 2023 22:53 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/11 "2023-03-09T22:53:15Z")

</div>

yes i need it on db2.0

---

<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:** [10 March 2023 09:02 UTC](https://discourse.nodered.org/t/change-query-from-1-8-to-2-0-db-influx/75820/12 "2023-03-10T09:02:25Z")

</div>

> [@Shwowak](#):
>
> Power values ​​from the Pv from the last day 0-24 hours

If you want it for the full 24 hours then you don't need the hourselection at all. Each filter down the chain only removes records, so if you have already selected the day that you want then you don't need to select which hours you want, as you want all of them.
