I have a string with that contains characters that need escaping:
params = {
content: "Hello, I'm an AI designed to help you, your agent and your carrier"
}
to insert a row using the GUI mode I'd use
{{ params.content }}
and the retool backend would escape the string properly. I'm now going back and combining a bunch of workflow blocks into a single SQL statement or moving them to the query library, both of which require using SQL mode.
INSERT INTO
ainsure_messages (
"created_on",
"updated_on",
"created_by",
"content",
"thread_id",
"source",
"role",
"platform",
"agency",
"from",
"to"
)
VALUES
(
TO_TIMESTAMP ({{ createThread.data.created_at }}),
TO_TIMESTAMP ({{ createThread.data.created_at }}),
'{{ params.user_id }}',
'{{ params..content }}',
'{{ insertNewThread.data[0].thread_id }}',
'{{ params.source }}',
'{{ params.role }}',
'retool_desktop',
'{{ params.agency }}',
'ai',
'{{ params.role }}'
);
when using the value up at the top (the hello message) this throws an error:
It took me a while to figure out the m
it's referring to is actually in the evaluated expression... it took me even longer to figure the proper way to escape this. I tried using the psql functions quote_literal
and quote_nullable
since postgresql seems to use '
as the escape character instead of \
like JS but this didn't work either. I ended up having to use JS .replace():
INSERT INTO
ainsure_messages (
"created_on",
"updated_on",
"created_by",
"content",
"thread_id",
"source",
"role",
"platform",
"agency",
"from",
"to"
)
VALUES
(
TO_TIMESTAMP ({{ createThread.data.created_at }}),
TO_TIMESTAMP ({{ createThread.data.created_at }}),
'{{ params.user_id }}',
'{{ params.messages[0].content.replace("'", "''") }}',
'{{ insertNewThread.data[0].thread_id }}',
'{{ params.source }}',
'{{ params.role }}',
'retool_desktop',
'{{ params.agency }}',
'ai',
'{{ params.role }}'
);
I'm guessing this is intended, but since the GUI mode does this behind the scenes you need indepth knowledge to figure this out. Would it be possible to make it so retool automatically escapes text columns even in SQL mode to avoid having to remember to do this everywhere?