# Passing parameters to stored procedure (PostgreSQL) causes syntax error

**URL:** https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211
**Category:** General
**Created:** [29 September 2025 09:02 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211 "2025-09-29T09:02:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Karsten](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@Karsten](https://discourse.nodered.org/u/Karsten)
#### Post date: [29 September 2025 09:02 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211/1 "2025-09-29T09:02:20Z")

</div>

Dear community,  
I am sharing my node with you. I would like to pass three parameters to a stored procedure. Unfortunately, this fails with a syntax error. Can you please help me out? It concerns the part of the node shown in the screenshot.

### Procedure

```sql
CREATE OR REPLACE FUNCTION "Berger".update_(at_ numeric, waermebedarf_ numeric, flag_ character varying)
 RETURNS character varying
 LANGUAGE sql
AS $function$
update "Berger".messwerte
set waermebedarf = waermebedarf_, flag = flag_
where (at = at_ and flag = 'd')
or (at = at_ and flag = 'm' and waermebedarf_ > waermebedarf);
select 'ok';
;
$function$
;

```

### Flow

```json
[
    {
        "id": "c6281932c6357d5f",
        "type": "tab",
        "label": "Spielwiese",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "eccfa5c56b79ee3d",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-23.3",
        "payloadType": "num",
        "x": 130,
        "y": 40,
        "wires": [
            [
                "07ed769f880c4635"
            ]
        ]
    },
    {
        "id": "07ed769f880c4635",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "Abfrage Wert >20 oder<-30 und runden",
        "func": "var wert_neu = {wert: Math.round(msg.payload)}\nif (wert_neu.wert > 20 || wert_neu.wert < -30)\n{\n msg.payload = 999 \n}\nelse\n{\n msg.payload = wert_neu.wert\n}\n\nmsg.topic = \"aussentemperatur\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 40,
        "wires": [
            [
                "2faab1428884202a",
                "2d4aac0138418a6e"
            ]
        ]
    },
    {
        "id": "5697388293e21580",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "500.8",
        "payloadType": "num",
        "x": 110,
        "y": 140,
        "wires": [
            [
                "da2c364dea10a442",
                "db7ce56e354a7564"
            ]
        ]
    },
    {
        "id": "da2c364dea10a442",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "Waermemenge",
        "func": "msg.topic = \"waermemenge\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 140,
        "wires": [
            [
                "2faab1428884202a"
            ]
        ]
    },
    {
        "id": "94141b471918e7d9",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 15",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.aussentemperatur",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 40,
        "wires": []
    },
    {
        "id": "2faab1428884202a",
        "type": "join",
        "z": "c6281932c6357d5f",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 630,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "41579c00b64ffe6c",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.waermemenge",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 140,
        "wires": []
    },
    {
        "id": "b7065d8d30924906",
        "type": "comment",
        "z": "c6281932c6357d5f",
        "name": "prüfen",
        "info": "/*select \"Berger\".update_({{msg.payload.at_}}, {{msg.payload.waermebedarf}}, {{msg.payload.status}}) */",
        "x": 730,
        "y": 520,
        "wires": []
    },
    {
        "id": "a11d6889584aa143",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 520,
        "wires": [
            [
                "327342951cf3cbb4"
            ]
        ]
    },
    {
        "id": "327342951cf3cbb4",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 6",
        "func": "var at_ = -2\nvar waermebedarf = 2000\nvar status = 'm'\n/*\nmsg.payload =\n{\n at_: at_,\n waermebedarf: waermebedarf,\n status: status\n}\n*/\nmsg.params = [at_, waermebedarf, status]\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 520,
        "wires": [
            [
                "0c18d08db435201a"
            ]
        ]
    },
    {
        "id": "2d4aac0138418a6e",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 7",
        "func": "flow.set (\"sensor_at\", msg.payload)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "db7ce56e354a7564",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 8",
        "func": "flow.set (\"sensor_waerme\", msg.payload)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "c58205ffbcb7f5f5",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 9",
        "func": "let sensor_1 = flow.get(\"sensor_at\")\nlet sensor_2 = flow.get(\"sensor_waerme\")\nlet msg1 = {payload: sensor_1}\nlet msg2 = {payload: sensor_2}\nlet msg3 = {payload: \"\"}\nif (sensor_1 !== undefined && sensor_1 !== 999 && sensor_2 !== undefined)\n{\n msg1 = { payload: sensor_1 }\n msg2 = { payload: sensor_2 }\n msg3 = { payload: \"m\" } \n}\n\nreturn [msg1,msg2, msg3];",
        "outputs": 3,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 340,
        "wires": [
            [
                "fe03f6409bbc0a56"
            ],
            [
                "1a406871004f06c3"
            ],
            [
                "387d595141b1b3a4"
            ]
        ]
    },
    {
        "id": "fa06128dc3301892",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 340,
        "wires": [
            [
                "c58205ffbcb7f5f5"
            ]
        ]
    },
    {
        "id": "fe03f6409bbc0a56",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 24",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 320,
        "wires": []
    },
    {
        "id": "1a406871004f06c3",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 360,
        "wires": []
    },
    {
        "id": "387d595141b1b3a4",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 26",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 420,
        "wires": []
    },
    {
        "id": "0c18d08db435201a",
        "type": "pg",
        "z": "c6281932c6357d5f",
        "name": "",
        "query": "select \"Berger\".update_($1, $2, $3)",
        "pgConfig": "e38b9fdc4da34774",
        "outputFormat": "mul",
        "x": 530,
        "y": 520,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "e38b9fdc4da34774",
        "type": "pgConfig",
        "name": "postgres",
        "host": "127.0.0.1",
        "port": "5432",
        "dbname": "template1",
        "max": "10",
        "idleTimeout": "1000",
        "connectionTimeout": "10000",
        "user": "postgres",
        "password": "postgres"
    }
]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/8990e57e2fe5cf3513f31bcdd911361401a98678.png)

ADMIN EDIT: Please post code into code blocks to avoid the need to download it!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [29 September 2025 10:14 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211/2 "2025-09-29T10:14:12Z")

</div>

I would create 2 separate flows. Flow 1 - creates the function, flow 2 calls the function

See the README for that node to understand how to pass parameters via the msg object.

PS, please also provide link to the PG node you are using in the [flow library](https://flows.nodered.org/search?term=postgre&type=node)

---

<div class="post-metadata">

### Author: ![Karsten](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@Karsten](https://discourse.nodered.org/u/Karsten)
#### Post date: [29 September 2025 14:12 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211/3 "2025-09-29T14:12:39Z")

</div>

[node-red-contrib-postgresql](https://github.com/alexandrainst/node-red-contrib-postgresql)

---

<div class="post-metadata">

### Author: ![Karsten](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@Karsten](https://discourse.nodered.org/u/Karsten)
#### Post date: [29 September 2025 14:13 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211/4 "2025-09-29T14:13:51Z")

</div>

```json
[
    {
        "id": "c6281932c6357d5f",
        "type": "tab",
        "label": "Spielwiese",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "eccfa5c56b79ee3d",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-23.3",
        "payloadType": "num",
        "x": 130,
        "y": 40,
        "wires": [
            [
                "07ed769f880c4635"
            ]
        ]
    },
    {
        "id": "07ed769f880c4635",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "Abfrage Wert >20 oder<-30 und runden",
        "func": "var wert_neu = {wert: Math.round(msg.payload)}\nif (wert_neu.wert > 20 || wert_neu.wert < -30)\n{\n msg.payload = 999 \n}\nelse\n{\n msg.payload = wert_neu.wert\n}\n\nmsg.topic = \"aussentemperatur\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 40,
        "wires": [
            [
                "2faab1428884202a",
                "2d4aac0138418a6e"
            ]
        ]
    },
    {
        "id": "5697388293e21580",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "500.8",
        "payloadType": "num",
        "x": 110,
        "y": 140,
        "wires": [
            [
                "da2c364dea10a442",
                "db7ce56e354a7564"
            ]
        ]
    },
    {
        "id": "da2c364dea10a442",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "Waermemenge",
        "func": "msg.topic = \"waermemenge\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 140,
        "wires": [
            [
                "2faab1428884202a"
            ]
        ]
    },
    {
        "id": "94141b471918e7d9",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 15",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.aussentemperatur",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 40,
        "wires": []
    },
    {
        "id": "2faab1428884202a",
        "type": "join",
        "z": "c6281932c6357d5f",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 630,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "41579c00b64ffe6c",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.waermemenge",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 140,
        "wires": []
    },
    {
        "id": "b7065d8d30924906",
        "type": "comment",
        "z": "c6281932c6357d5f",
        "name": "prüfen",
        "info": "/*select \"Berger\".update_({{msg.payload.at_}}, {{msg.payload.waermebedarf}}, {{msg.payload.status}}) */",
        "x": 730,
        "y": 520,
        "wires": []
    },
    {
        "id": "a11d6889584aa143",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 520,
        "wires": [
            [
                "327342951cf3cbb4"
            ]
        ]
    },
    {
        "id": "327342951cf3cbb4",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 6",
        "func": "var at_ = -2\nvar waermebedarf = 2000\nvar status = 'm'\n/*\nmsg.payload =\n{\n at_: at_,\n waermebedarf: waermebedarf,\n status: status\n}\n*/\nmsg.params = [at_, waermebedarf, status]\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 520,
        "wires": [
            [
                "0c18d08db435201a"
            ]
        ]
    },
    {
        "id": "2d4aac0138418a6e",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 7",
        "func": "flow.set (\"sensor_at\", msg.payload)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "db7ce56e354a7564",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 8",
        "func": "flow.set (\"sensor_waerme\", msg.payload)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "c58205ffbcb7f5f5",
        "type": "function",
        "z": "c6281932c6357d5f",
        "name": "function 9",
        "func": "let sensor_1 = flow.get(\"sensor_at\")\nlet sensor_2 = flow.get(\"sensor_waerme\")\nlet msg1 = {payload: sensor_1}\nlet msg2 = {payload: sensor_2}\nlet msg3 = {payload: \"\"}\nif (sensor_1 !== undefined && sensor_1 !== 999 && sensor_2 !== undefined)\n{\n msg1 = { payload: sensor_1 }\n msg2 = { payload: sensor_2 }\n msg3 = { payload: \"m\" } \n}\n\nreturn [msg1,msg2, msg3];",
        "outputs": 3,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 340,
        "wires": [
            [
                "fe03f6409bbc0a56"
            ],
            [
                "1a406871004f06c3"
            ],
            [
                "387d595141b1b3a4"
            ]
        ]
    },
    {
        "id": "fa06128dc3301892",
        "type": "inject",
        "z": "c6281932c6357d5f",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 340,
        "wires": [
            [
                "c58205ffbcb7f5f5"
            ]
        ]
    },
    {
        "id": "fe03f6409bbc0a56",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 24",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 320,
        "wires": []
    },
    {
        "id": "1a406871004f06c3",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 360,
        "wires": []
    },
    {
        "id": "387d595141b1b3a4",
        "type": "debug",
        "z": "c6281932c6357d5f",
        "name": "debug 26",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 420,
        "wires": []
    },
    {
        "id": "0c18d08db435201a",
        "type": "pg",
        "z": "c6281932c6357d5f",
        "name": "",
        "query": "select \"Berger\".update_($1, $2, $3)",
        "pgConfig": "e38b9fdc4da34774",
        "outputFormat": "mul",
        "x": 530,
        "y": 520,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "e38b9fdc4da34774",
        "type": "pgConfig",
        "name": "postgres",
        "host": "127.0.0.1",
        "port": "5432",
        "dbname": "template1",
        "max": "10",
        "idleTimeout": "1000",
        "connectionTimeout": "10000",
        "user": "postgres",
        "password": "postgres"
    }
]

```

---

<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: [28 December 2025 14:13 UTC](https://discourse.nodered.org/t/passing-parameters-to-stored-procedure-postgresql-causes-syntax-error/99211/5 "2025-12-28T14:13:57Z")

</div>

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