# Delete table records and table in postgresql - issue in table name

**URL:** <https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475>\
**Category:** General\
**Tags:** node-red-dashboard, database\
**Created:** [19 April 2022 06:57 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475 "2022-04-19T06:57:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 06:57 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/1 "2022-04-19T06:57:23Z")

</div>

hi, all i want to delete table and records, i used this query to delete, got error message. pls support. If i use table name instead of msg.payload, the query is working fine , able to delete table and records. what am i missing?

DROP TABLE IF EXISTS ('{{msg.payload}}');  
DELETE FROM where tablename='{{msg.payload}}';

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/0458ab9450839894a8be7e025b34bd3dbf95e7ed.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b500cf43c304e2c0fc059936d00a2ea65a563ec.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 April 2022 07:11 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/2 "2022-04-19T07:11:00Z")

</div>

If this query is created in the template node, is the node set to mustache, Otherwise please tell us which node creates this query and post the flow.json of the nodes used.

---

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 07:17 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/3 "2022-04-19T07:17:46Z")

</div>

The query is created in postgresql node, not is template

[  
{  
"id": "8bd521c122332c1e",  
"type": "inject",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"props": [  
{  
"p": "payload"  
}  
],  
"repeat": "",  
"crontab": "",  
"once": true,  
"onceDelay": 0.1,  
"topic": "",  
"payload": "true",  
"payloadType": "bool",  
"x": 70,  
"y": 3160,  
"wires": [  
[  
"12af7b5e1bc34043"  
]  
]  
},  
{  
"id": "12af7b5e1bc34043",  
"type": "function",  
"z": "8bfb4aab88ac7972",  
"name": "set False",  
"func": "msg.enabled = false;\nreturn msg;",  
"outputs": 1,  
"noerr": 0,  
"initialize": "",  
"finalize": "",  
"libs": ,  
"x": 220,  
"y": 3160,  
"wires": [  
[  
"fe1e050c6aa877ec"  
]  
]  
},  
{  
"id": "a50635d8b57dce4f",  
"type": "change",  
"z": "8bfb4aab88ac7972",  
"name": "enabled false",  
"rules": [  
{  
"t": "set",  
"p": "enabled",  
"pt": "msg",  
"to": "false",  
"tot": "bool"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 160,  
"y": 3240,  
"wires": [  
[  
"fe1e050c6aa877ec"  
]  
]  
},  
{  
"id": "c88151a71093281e",  
"type": "change",  
"z": "8bfb4aab88ac7972",  
"name": "enabled true",  
"rules": [  
{  
"t": "set",  
"p": "enabled",  
"pt": "msg",  
"to": "true",  
"tot": "bool"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 170,  
"y": 3340,  
"wires": [  
[  
"fe1e050c6aa877ec"  
]  
]  
},  
{  
"id": "fe1e050c6aa877ec",  
"type": "ui\_button",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"group": "2722107c9c033306",  
"order": 4,  
"width": 0,  
"height": 0,  
"passthru": false,  
"label": "Delete Table",  
"tooltip": "",  
"color": "",  
"bgcolor": "",  
"className": "",  
"icon": "",  
"payload": "tablesdb",  
"payloadType": "global",  
"topic": "submit",  
"topicType": "msg",  
"x": 430,  
"y": 3220,  
"wires": [  
[  
"4895e1f0bd5dab7c",  
"a1bdcf5018d40310"  
]  
]  
},  
{  
"id": "4895e1f0bd5dab7c",  
"type": "template",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"field": "payload",  
"fieldType": "msg",  
"format": "handlebars",  
"syntax": "mustache",  
"template": "Delete Table: '{{payload}}' !",  
"output": "str",  
"x": 660,  
"y": 3220,  
"wires": [  
[  
"4b07af975c478e1b"  
]  
]  
},  
{  
"id": "4b07af975c478e1b",  
"type": "ui\_toast",  
"z": "8bfb4aab88ac7972",  
"position": "dialog",  
"displayTime": "3",  
"highlight": "",  
"sendall": true,  
"outputs": 1,  
"ok": "CANCEL",  
"cancel": "OK",  
"raw": false,  
"className": "",  
"topic": "Delete Table?",  
"name": "Delete Table?",  
"x": 920,  
"y": 3220,  
"wires": [  
[  
"f10891a815e4d7f6"  
]  
]  
},  
{  
"id": "cdc6028ede7f1277",  
"type": "ui\_toast",  
"z": "8bfb4aab88ac7972",  
"position": "top right",  
"displayTime": "3",  
"highlight": "",  
"sendall": true,  
"outputs": 0,  
"ok": "CANCEL",  
"cancel": "OK",  
"raw": false,  
"className": "",  
"topic": "Message:",  
"name": "Table is not deleted",  
"x": 1050,  
"y": 3420,  
"wires":   
},  
{  
"id": "304beea04bc5f013",  
"type": "postgrestor",  
"z": "8bfb4aab88ac7972",  
"name": "Table name selection",  
"query": "DROP TABLE IF EXISTS ('{{msg.payload}}');\n",  
"postgresDB": "d39353cd.91093",  
"output": true,  
"outputs": 1,  
"x": 1100,  
"y": 3320,  
"wires": [  
[  
"c1fefb3de52e94cf"  
]  
]  
},  
{  
"id": "ce2e15d1e7a00e26",  
"type": "change",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"rules": [  
{  
"t": "set",  
"p": "payload",  
"pt": "msg",  
"to": "tablesdb",  
"tot": "global"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 800,  
"y": 3320,  
"wires": [  
[  
"c0020c464e972e2d",  
"304beea04bc5f013"  
]  
]  
},  
{  
"id": "f10891a815e4d7f6",  
"type": "switch",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"property": "payload",  
"propertyType": "msg",  
"rules": [  
{  
"t": "eq",  
"v": "OK",  
"vt": "str"  
},  
{  
"t": "eq",  
"v": "CANCEL",  
"vt": "str"  
}  
],  
"checkall": "true",  
"repair": false,  
"outputs": 2,  
"x": 550,  
"y": 3340,  
"wires": [  
[  
"ce2e15d1e7a00e26",  
"f08f57107dade234",  
"a50635d8b57dce4f"  
],  
[  
"6cc0d9cf37a11282",  
"f08f57107dade234",  
"a50635d8b57dce4f"  
]  
]  
},  
{  
"id": "6cc0d9cf37a11282",  
"type": "function",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"func": "msg.payload = 'Table is not Deleted';\nreturn msg;",  
"outputs": 1,  
"noerr": 0,  
"initialize": "",  
"finalize": "",  
"libs": ,  
"x": 840,  
"y": 3420,  
"wires": [  
[  
"cdc6028ede7f1277"  
]  
]  
},  
{  
"id": "f08f57107dade234",  
"type": "change",  
"z": "8bfb4aab88ac7972",  
"name": "",  
"rules": [  
{  
"t": "set",  
"p": "payload",  
"pt": "msg",  
"to": "",  
"tot": "str"  
}  
],  
"action": "",  
"property": "",  
"from": "",  
"to": "",  
"reg": false,  
"x": 740,  
"y": 3520,  
"wires": [  
[  
"c17ffae8f161f987"  
]  
]  
},  
{  
"id": "2722107c9c033306",  
"type": "ui\_group",  
"name": "Delete all records",  
"tab": "5e17a74c595a0ca0",  
"order": 4,  
"disp": true,  
"width": "6",  
"collapse": false,  
"className": ""  
},  
{  
"id": "d39353cd.91093",  
"type": "postgresDB",  
"name": "postgres@127.0.0.1:5432/OEE",  
"host": "127.0.0.1",  
"hostFieldType": "str",  
"port": "5432",  
"portFieldType": "num",  
"database": "OEE",  
"databaseFieldType": "str",  
"ssl": "false",  
"sslFieldType": "bool",  
"max": "10",  
"maxFieldType": "num",  
"min": "1",  
"minFieldType": "num",  
"idle": "1000",  
"idleFieldType": "num",  
"connectionTimeout": "10000",  
"connectionTimeoutFieldType": "num",  
"user": "postgres",  
"userFieldType": "str",  
"password": "",  
"passwordFieldType": "str"  
},  
{  
"id": "5e17a74c595a0ca0",  
"type": "ui\_tab",  
"name": "Database settings",  
"icon": "dashboard",  
"order": 22,  
"disabled": false,  
"hidden": false  
}  
]

---

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 07:22 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/4 "2022-04-19T07:22:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/edff1d790a16f8899a371442a7d8a5ae46a6db3a.png)

---

<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:** [19 April 2022 07:31 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/5 "2022-04-19T07:31:02Z")

</div>

In your payload I can see the value **table 5**

Assuming the postgres node you are using actually support mustache syntax then you should add double quotes around it.

E.g. `"{{payload}}"`

---

<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:** [19 April 2022 07:31 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/6 "2022-04-19T07:31:40Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 07:37 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/7 "2022-04-19T07:37:11Z")

</div>

Hi Thanks lot, it is working perfectly , now able to delete the table in database, also records in table, I missed out the double quotes

---

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 12:44 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/8 "2022-04-19T12:44:17Z")

</div>

Hi m creating Query editor to create table in database from Node red;

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/882bdedc57566dd55ee6be75cefa4fafefb8a3e2.png)  
after create , getting msg payload  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce6acd578344f3424562336c21816206c7788e28.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4bc5604f9c798ae4014697af431bcec3e9beff06.png)

Postgresql node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db04e7bf795009d9f6d0adf87700affa659590ea.png)

m getting error, if i paste only query in postgresql able to create table, i tried double quotes got syntax error

---

<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:** [19 April 2022 13:02 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/9 "2022-04-19T13:02:40Z")

</div>

1. Remove the quotes (not necessary here)
2. Try using triple curly brackets to avoid escaping e.g. `{{{payload.query}}}`

---

<div class="post-metadata">

**Author:** ![learnobyte](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@learnobyte](https://discourse.nodered.org/u/learnobyte)\
**Post date:** [19 April 2022 13:22 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/10 "2022-04-19T13:22:35Z")

</div>

yes, it is working perfectly, what is the logic behind this, m not able to understand, any reference ?  
Now i can add table from query editor, delete table and records, Thanks lot,

---

<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:** [3 May 2022 13:22 UTC](https://discourse.nodered.org/t/delete-table-records-and-table-in-postgresql-issue-in-table-name/61475/11 "2022-05-03T13:22:59Z")

</div>

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