# How to use mustache template in inserting array into sql table

**URL:** https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724
**Category:** General
**Created:** [20 March 2023 05:30 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724 "2023-03-20T05:30:16Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kjbambe](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@kjbambe](https://discourse.nodered.org/u/kjbambe)
#### Post date: [20 March 2023 05:30 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/1 "2023-03-20T05:30:16Z")

</div>

Hello, im a newbie here. I am reading the documentation here [mustache(5) - Logic-less templates.](http://mustache.github.io/mustache.5.html)  
but it is not clear how to insert an array data into my sql table. I want to input my array data (image 1) into an sql table with columns name, codename. When i do it in a template node(image2) , i got an error message of syntax error. this is the output of the msg.query of the template node(image3). and the error is because of the syntax, the comma at the last vallue of the array. How can it be fixed? Any help will be much appreciated 🙂

---

<div class="post-metadata">

### Author: ![kjbambe](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@kjbambe](https://discourse.nodered.org/u/kjbambe)
#### Post date: [20 March 2023 05:31 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/2 "2023-03-20T05:31:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57ef1a256d3d41a8dd6617c1b54c85a16f876d55.png)

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

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

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 05:49 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/3 "2023-03-20T05:49:03Z")

</div>

As much as I would like to be a _database_ person.....

Why can't you delete the last `,`?

You should paste the code/s rather than screen-shot'ing the pictures.  
It would help and make it a lot easier for people to help you.

---

<div class="post-metadata">

### Author: ![kjbambe](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@kjbambe](https://discourse.nodered.org/u/kjbambe)
#### Post date: [20 March 2023 05:52 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/4 "2023-03-20T05:52:32Z")

</div>

Hello, the image with last , is the result of the msg.query from the template node so I cannot edit that.  
Sorry i cannot pastes code/s.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 05:55 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/5 "2023-03-20T05:55:17Z")

</div>

You can post code/s.

You just have to learn how to.

The `</>` button is used to allow you to paste code.

Exporting from your end is done with the EXPORT of the MENU of Node-Red (Top right corner - _burger bar_ icon.)

Copying/pasting `debug` is done from the small `clipboard` icon to the right of the message in the `debug` window.

---

<div class="post-metadata">

### Author: ![kjbambe](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@kjbambe](https://discourse.nodered.org/u/kjbambe)
#### Post date: [20 March 2023 06:34 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/6 "2023-03-20T06:34:02Z")

</div>

Sorry i mean i cannot pastes my codes as it is confidential. I want to ask more on a general ways of doing thing in nodered.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 06:36 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/7 "2023-03-20T06:36:14Z")

</div>

You should be able to cut down to nodes that do the basics of what you want to do.

Then post that as a base-line.

Then people can see (better) what you want to do and help you quicker.

You then get their answer and _tweak_ them to your needs.

---

<div class="post-metadata">

### Author: ![kjbambe](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@kjbambe](https://discourse.nodered.org/u/kjbambe)
#### Post date: [20 March 2023 07:33 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/8 "2023-03-20T07:33:46Z")

</div>

[SOLVED]  
the {{#payload}} should be on the top most before the INSERT INTO and the  
{{/payload}} should be on the bottom after the ON CONFLICT statement.

---

<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 April 2023 07:34 UTC](https://discourse.nodered.org/t/how-to-use-mustache-template-in-inserting-array-into-sql-table/76724/9 "2023-04-03T07:34:13Z")

</div>

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