Dynamic query parameters not updating between executions in PostgreSQL queries

Problem Description

I’m using an n8n workflow to fetch content from a PostgreSQL database (public.contents table) based on a dynamic section_id. The workflow uses a PostgreSQL node to execute a query:

SELECT content
FROM public.contents
WHERE section_id = $1;

The section_id parameter is dynamically set using the queryReplacement option within the n8n PostgreSQL node:

{{ $fromAI('section_id') }}

Issue:

The issue is that the query seems to cache the section_id value from the first execution. Subsequent runs of the workflow with different section_id values incorrectly return the content associated with the original section_id. No error messages are displayed. The issue appears to be related to how the dynamic parameter (section_id) is being handled by the PostgreSQL node.

Observed Behavior:

  • First Execution: Correct content is fetched for the given section_id.
// Input:
{
    "section_id": "657dad6b-42a6-4990-8091-8b5c7d11af24"
}

// Output:
{
  "content": "Content for section_id 657dad6b-42a6-4990-8091-8b5c7d11af24"
}
  • Second Execution: Incorrectly returns the same content as the first execution, even with a new section_id.
// Input:
{
   "section_id": "9b24f8e5-d08e-4567-93b3-5cabc1234567"
}

// Output:
{
   "content": "Content for section_id 657dad6b-42a6-4990-8091-8b5c7d11af24"
}

Workflow Configuration (JSON):

Environment:

  • n8n version: 1.70.3

  • Database: PostgreSQL

  • n8n EXECUTIONS_PROCESS setting: Railway Execution

  • Running n8n via: Railway

  • Operating system: Ubuntu (likely)

Screenshots:

Hey @Joaquin_Mulet

Can you try updating? There was a bug where tools were not looping correctly so it would always use the first item but I think that is now resolved.

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