Problem when inserting long message in postgres node

Describe the problem/error/question

I’m having a problem when I try to insert a long message inside my Postgress database. It’s truncating my message from 812 characters to about 269 characters.

This is my query inside the Postgres Node:

INSERT INTO pbm.messages (
conversation_id, direction, text_raw, text_norm, payload
) VALUES (
$1, ‘outbound’,
$2,
$2,
‘{}’::jsonb
);

Query parameters:
{{ $node[“Criar conversa ativa (/pbm)”].json.conversation_id }},
{{ $json.conversation.message }}

The problem occurs when the placeholder $2 gets the content of the parameter {{ $json.conversation.message }}. Somehow, it’s truncating when inserting in my postgres database column.

If I do something like:

INSERT INTO pbm.messages (
conversation_id, direction, text_raw, text_norm, payload
) VALUES (
$1, ‘outbound’,
$$ {{ $json.conversation.message }} $$,
$$ {{ $json.conversation.message }} $$,
‘{}’::jsonb
);

The error doesn’t occur anymore if I try the workaround above, but I guess it makes me vulnerable to SQL injection problems.

The message I’m trying to insert is:
:waving_hand: Bem-vindo(a) ao Assistente de Suporte ao módulo de Patient Blood Management (PBM) focado no Pilar 1: Detecção e tratamento da anemia no pré-operatório

Você está interagindo com um sistema de apoio clínico baseado nos princípios do Patient Blood Management (PBM), conforme o Consenso da Associação Brasileira de Hematologia, Hemoterapia e Terapia Celular (ABHH) e as Diretrizes do CPOC (Centre for Perioperative Care).

:drop_of_blood: Objetivo: Apoiar médicos na avaliação, diagnóstico e manejo da anemia perioperatória e na adoção de condutas baseadas em evidências, em todos os momentos do pré-operatório, sempre respeitando o julgamento clínico individual.

:warning: Importante: Este assistente não substitui a decisão médica. Ele fornece orientações baseadas em protocolos para apoiar sua prática clínica.
**
But then it gets stored as:**

workflow:

Information on your n8n setup

  • n8n version: Version 1.114.4
  • Database : Postgres
  • Running n8n via: Docker (VPS)