Execute SQL Query from an array object

Hi Everyone, i'm new to node-red, can anyone help me with this, i'm trying to load get data from Servicely Api and load it to SQL table, i'm trying to run the query which come from an array object, i'm getting the "RequestError: Incorrect syntax near ','." error, the following is the output from the Debug node

Welcome to the forum @Mabona745

Do you mean that you want to run the query that is in msg.payload[0].query? If so then use a Change node to Move msg.payload[0].query To wherever the query should be for you database node, possibly msg.topic, it depends on which node you are using.

If you mean that you want to run all the (in this case) 200 queries in the array then use a Split node to split it into 200 separate messages, then you can use a Change node to move msg.payload.query into the appropriate property.

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thank you Colin

Hi Colin, i hope you well, i want to get a data from paginated servicely API, i can do anything up until i have to insert the data into the table, have a look at the screenshot below.

the node: Debug 127 give me the following

,which is fine, now i want to run the output on sql node and i'm getting the following error,
image

the format SQL Insert statements is just a simple insert statement

I just don't know where i'm going wrong.... Can you please help if you can ?

At first you said

Your SQL seems to contain the character sequence ','.
You need to find this sequence and fix the code which generates it.

Your task is made harder because the SQL query is too long to be fully shown in the output of a debug node. Use a write file node to save the query and you can then examine it in detail.

The task of people here trying to help you is made harder because you posted screen captures instead of text.
We cannot copy your SQL code into a text editor and search it for the character sequence.

If you had copied the text of this function and pasted it here (using the </> button) we could verify that it seems OK. But we can't because you posted a picture, not even showing the whole query.

It looks like you are trying to save some free form text, perhaps from a web form. Are you taking steps to sanitise the data to prevent malicious SQL insertion and accidental use of apostrophes?

Do you expect [image: image.png] to be saved to the database as those exact characters or as a picture?

1 Like