Passing column entries as comma separated list to postgres SQL query

I have read an excel sheet with a single column and 700 rows in it.

I would like to pass the entries of this column comma separated to a postgres SQL query to filter the data for entries present in the above column.

Currently the postgres SQL node takes input of the first entry of the column alone.

select * from table1 where table1.column1 in (row1,row2,row3…)

I would like to pass the row entries in the in command in SQL


Hey @Srinath_V, welcome to the community :tada:

In a first step you’d need to convert the 700 individual items from each row into a single item that has the required format 'row1','row2','row3' (assuming your database holds text values).

This could be done in Function node running code like this (this assumes your spreadsheet column is called names, replace as needed):

return [{
  json: {
    all_rows: => `'${e.json.names}'`).join(',')

The output should look like so:

In your PostgreSQL node you can then use this value in your query. Select the Execute Query operation and add an expression like so:

Then use an expression like SELECT * FROM dummy WHERE message IN ({{$json["all_rows"]}}); (replace dummy with your table name and message with your column name):

This should give you the query you have in mind. Let me know if you have any questions on this!

This worked, Thanks a lot for your support!!

1 Like

Excellent, I am glad to hear that. Thanks so much for confirming!