How to batch the return values of a Postgres/Supabase node?

Describe the problem/error/question

I have 2 consecutive postgres nodes. The first selects 2 records from a table, and the second uses those record IDs to lookup records in a second table. Using those 2 record IDs as inputs, the second node returns 3 records in total, as expected. Great!

My issues is that those 3 records are grouped together and passed to the next node, and I lose the “connection” between those records and the initial record I used as the lookup ID. Ultimately, my goal is to work out which of my IDs are linked to a single record, and which are linked to multiple records. But I can’t seem to do this as the next node (whichever one I use) just sees 3 records as an input.

For example, using the workflow below, lookup ID 111 returns record AAA, and lookup ID 222 returns records BBB and CCC. But I don’t want to pass AAA, BBB and CCC to the next node as 3 inputs. I kinda want to send 2 arrays, [AAA] and [BBB, CCC]. I hope that kinda makes sense. I’m sorry for not being very clear. :frowning:

Thank you!

What is the error message (if any)?

N/A

Please share your workflow

Share the output returned by the last node

I’d love for the second Postgres node to output two values (related to the two input IDs), not 3 individual values (or to understand what the workaround is).

Information on your n8n setup

  • n8n version: 1.18.0
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: MacOS

Hi @brandrsn, welcome to the community!

I’d love for the second Postgres node to output two values (related to the two input IDs), not 3 individual values (or to understand what the workaround is).

This does make sense! Perhaps you want to consider adding a Loop Over Items node after your first Postgres node and break down your data in batches of 1 item each? Then execute the second Postgres node inside the loop and send the respective results to the Item List node building the array before closing the loop.

This should leave you with two items after the loop.

Give me a shout if I this isn’t working (or in case I have missed something else here) :slight_smile:

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