I’m completely stuck with a PostgreSQL Lookup node in n8n. I’m trying to match a chat_id against a value stored in my database. The chat_id column is of type TEXT, and the value I’m passing into the node is 100% correct.
I’m using this as the query:
SELECT * FROM public.conversations WHERE chat_id = $1::text;
And I’m passing the value using this expression: {{ $node["ChatID Extraktion"].json["chat_id"].toString().trim() }}
Despite this, the query returns no results, even though the ID is clearly in the database.
What I’ve already checked:
The chat_id exists in the DB and matches exactly
No extra whitespace or formatting issues
If I hardcode the value directly into the query, it works
I also tried converting everything to hex – turns out the incoming value is fine (3637...) but at some point n8n seems to pass the expression as a literal string, not as an evaluated value
It’s like the parameter isn’t being resolved correctly. I even tried various casting approaches, LIKE queries, etc. Still no results.
I’m losing my mind at this point. Has anyone had this issue where the value just doesn’t resolve or match in a query, even though all formatting and types seem fine?
Would seriously appreciate any ideas. Thanks in advance.
Still doesn’t work. I even deleted the database and set it up from scratch. The ‘ChatID extraction’ now takes exactly the value that comes from the node’s output. Before, I was using {{ $('Telegram Trigger').item.json.message.chat.id }} directly. I thought that might be the issue, but unfortunately the Chat ID still isn’t being passed correctly. Still, thank you so much for trying to help me
Yes, @Sudhanshu_Sharma when I enter the chat ID manually, it’s just not recognized as an expression. You can see it in the screenshot — once with the chat ID entered manually, and once using the expression directly from the ChatID extraction.
It was a pretty weird issue involving the PostgREST node.
The issue:
He was trying to get a record from a table using an SQL query. When he passed the chat_id directly, everything worked fine. But when using an expression, it wasn’t returning the expected output.
We tried 2–3 different methods to solve this…it was honestly a bit crazy.
But finally, we found a solution that worked for him!
The Solution:
Instead of using the “Execute SQL” operation to retrieve the row, we used the default n8n operation “Select a row from the table”, and it worked!
Sometimes the simplest solutions are the hardest to find. I’m really happy that he can finally move forward!
@MN_Agency , please share the workflow here for future reference.