I’m trying to prepare a query in a code block and insert it in a retool db block without GUI. Since it’s a bulk upsert with with composite primary key. This is not supported with the GUI as far as I know.
This just outputs the result of the previous block that’s the query variable that was returned.
I get the error:
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
When changing this setting my apps stop working because they need this setting. The workflow works when this setting is changed though.
So I’m stuck. Is there another way to get this working? I need the values inserted in this query somehow.
I ended up disabling it for the entire resource and manually updated the 5-10 apps broken from this change, but will probably need to re-enable due to security of the query injection prevention.
Can you maybe duplicate the resource, with one for prepared statements disabled?
Prepared statements doesn't support dynamic table names (i.e. you can't have the table name inside {{}}), so we usually recommend @trz-justin-dev's suggestion of duplicating the resource. Having a separate resource with prepared statements off limits security concern & helps to ensure your other queries continue to work
Would it work if I just inserted the query in the query box and spread the values there? I’m not sure how to go about this.
INSERT INTO
app_po_items (po_id, variant_id, barcode)
VALUES
//values here somehow?
ON CONFLICT (po_id, variant_id) DO
UPDATE
SET
barcode = EXCLUDED.barcode;