In an app, I am programmatically building a sql query in a transformer, to then be used in a retool database resource query. When running the query, I am getting the same thing others have gotten – Error in converting query to prepared statement. You can disable this feature by checking the 'Disable converting queries to prepared statements' checkbox on the resource configuration page.
I have over 20 applications using the Retool Database Resource, so I can’t disable this feature. A recommended approach was to create a duplicate resource, only difference being this disabled feature. However, I can’t figure out how to create a second Retool Database Resource, so I can’t disable it. Any ideas on how to do it?
FWIW – below is the extent of the query in the transformer.
const includeUnprocessed = {{ checkbox1.value }};
const categories = {{ multiselect1.value }}.map(c => `'${c}'`);
const onlyShowCasesWithActions = {{ checkbox2.value }};
let sql = `
SELECT *
FROM some_case
WHERE TRUE
AND initially_processed = ANY(ARRAY[${ includeUnprocessed ? [true, false] : [true] }])
AND EXISTS (
SELECT *
FROM run_result_overall result_overall
WHERE result_overall.case_id = some_case.case_id
AND result_overall.email_category = ANY(ARRAY[${ categories }])
)
`;
if(onlyShowCasesWithActions) {
sql += `
AND EXISTS (
SELECT *
FROM run_result_overall result_overall
JOIN run_result_actions result_actions
ON result_actions.case_id = some_case.case_id
AND result_actions.workflow_run_id = result_overall.workflow_run_id
WHERE result_overall.case_id = some_case.case_id
)
`
}
return sql.replace(/\s+/g, ' ').trim();
What I don’t completely understand, is if I were to view the above transformers value (in state), copy/paste that to the Retool Database Resource Query’s SQL box, it works great. Here is an example of the transformer value:
SELECT * FROM some_case WHERE TRUE AND initially_processed = ANY(ARRAY[true,false]) AND EXISTS ( SELECT * FROM run_result_overall result_overall WHERE result_overall.case_id = some_case.case_id AND result_overall.email_category = ANY(ARRAY['Update Admin','Spam or Auto Response']) )


