Cannot write to Retool database?

I created a Retool database to use for my data. I then created a workflow that queries the Intercom API, does some transformations and on the final step should write to the Retool database. But I keep running into errors. I checked the settings for the database and tried to change it to write but it appears I cannot either. What are my options?

The last step in my workflow looks like this:
INSERT INTO aggregated_metrics (team_name, total_conversations, closed_conversations, median_response_time, last_updated)
VALUES {{ code1.map(metric => ( '${metric.teamName.replace(/'/g, "''")}', -- Escape single quotes in team names ${metric.totalConversations}, ${metric.closedConversations}, ${metric.medianFirstResponseTime || 'NULL'}, -- Handle null values NOW() )).join(", ") }}
ON CONFLICT (team_name) DO UPDATE
SET
total_conversations = EXCLUDED.total_conversations,
closed_conversations = EXCLUDED.closed_conversations,
median_response_time = EXCLUDED.median_response_time,
last_updated = EXCLUDED.last_updated;

1 Like

Hi @exhaustedmongoose can you please share screenshot or video to clear your issue?

Hey @exhaustedmongoose, assuming code1 is a JS block in your workflow that returns an array of objects, please replace code1.map(... with code1.data.map(....

You must access data returned by a JS block, via <block_name>.data. See this section of the Retool docs for further clarity.

Hope this helps.

Abdul Wasae
Toolshed

1 Like

Hi @exhaustedmongoose,

Just checking in here! Are you still working on this query?

Hey @exhaustedmongoose, welcome to the forum! :wave:

To better understand your issue, could you provide some additional details along with a screenshot? It would be helpful to know more about your workflow and the specific error message you're encountering—whether it's coming from Retool, your database, or a query. Let me know, and I'd be happy to help!

4 Likes