Hello n8n community,
I’m encountering an issue when trying to repeatedly execute the PostgreSQL tool using data split out from a previous node.
Here’s my workflow:
- Split Out Node: This node splits an array of items into individual items:.
- PostgreSQL Tool Node: This node executes the following query:
SQLSELECT year, SUM(revenue) AS total_revenue FROM industry_output WHERE industry_label = 'AI' AND industry_track = 'SOC' AND year IN (2019, 2020, 2021, 2022, 2023) GROUP BY year ORDER BY year;
My goal is to execute this PostgreSQL query for each item produced by the Split Out node. However, I’m finding that the PostgreSQL tool only executes once, using the data from the first item.
Here are my specific questions:
- How can I configure the PostgreSQL tool to execute the query for each item generated by the Split Out node?
- Is there a way to pass data from the Split Out node into the PostgreSQL query, such as using variables in the WHERE clause?
- Are there any work arounds to achieve this goal?
Any assistance or guidance would be greatly appreciated.
Thank you!
Hey, is there a specific reason you are putting the postgres as a tool for the AI agent ? Why not just use an execute SQL query node before or after the AI agent node ?
The reason for integrating PostgreSQL as a tool for the AI agent, rather than just using an execute SQL query node before or after, is that the previous split node passes a dynamically changing parameter, industry_track. The AI agent needs to continuously query multiple different industry_track values, such as “AIchip,” “SoC,” and so on. Having PostgreSQL directly accessible allows the agent to handle these dynamic queries efficiently within its workflow.
So if I understand well, your agent can only execute this particular query and in your prompt, you have something like specific triggers for the AI to execute this query (e.g : if a certain condition is met, use the query tool X times) ?
Normally, from what I understand from your workflow, is that the AI agent is called for each item generated by the split node, so I guess it doesn’t call the tool for a reason (maybe the prompt or something else ?), could you share the workflow so I can understand the problem better and test some things ?
Tanks for your help, I’ve managed to fix it with loop node 
1 Like