Hi everybody,
I would like to know if it is possible to transform the result of a postgres query like this one:
order_line_item_id sku qte status
9778452 XXX 1 CANCEL
9788453 XXXX 2 SHIPPED
in a csv file like this :
order_line_item_id/1;sku/1;qte/1;status/1;order_line_item_id/2;sku/2;qte/2;status/2
9778452;XXX;1;CANCEL;9788453;XXXX;2;SHIPPED
Thanks,
I have read this documentation but I am a real noob with n8n and I confess I did not understand how to go from 2 rows of sql answers to one row in my csv file
To do that you would need a ‘set’ node to define all the columns that you want in your CSV file. You could then fill in the values by referencing specific items in the output. Perhaps @harshil1712 can provide more details.
You can copy and paste the above code in the Editor UI. I am using the HTTP Request node to fetch dummy data from an API, in your case you will be using the Postgres node. In the Set node, I configure the values that I want to add in the CSV.
OK I understand what you are doing. In absolute terms it works, but I left out one important detail, the result of the query never has the same number of rows. The set node remains a static mode while I need a dynamic mode
@fporta, do you mean columns, or do you mean rows? If it’s the rows, then it is completely fine. The Set node will process all the incoming rows and the Spreadsheet File node will add all the rows to the CSV.
I realise that I have not been very clear in my explanations. My sql returns from 1 to n rows. The common point of these rows is the value of the order_id column (see screen)
I would like to achieve this:
order_id,order_line_item_id1,sku1,quantity1,status1,order_line_item_id2,sku2,quantity2,status2,order_line_item_id3,sku3,quantity3,status3
123456,978452,XXXXXXXX,2,CANCEL,978453,XXXXXXXX,2,SHIPPED,978451,1,REFUND
the number of columns is variable depending on the number of sql returns…