The thing I'm encountering is that I want to reuse this where block across multiple queries, but no matter what I try, like putting it into a transformer or JavaScript snippet, or whatever it is, I'm not able later on to insert it in multiple queries as text, so I have to duplicate it. How can I put it somewhere and then just reference it as a variable within multiple queries?
Hey guys, I feel very lonely here. It is a very simple thing I'm trying to do, but I'm fighting with it for a couple of days. How can I just insert a text into the query so it would be not as a variable, so that I can just reuse some part of the query across multiple items, but I will edit it from single interface like a variable. How to insert a variable in there or something, but so that it will be translated into query? {{{}}} Triple curly braces do not work; it is still inserted as a variable.
Thank you so much Miguel! It actually partially worked. The thing is, if I disable prepared statements, I can insert the contents of the variable into the query, but I lose the ability to dynamically reference variables as I did before. To understand it correctly, so there is no way to keep prepared statements but allow me to reuse some text from a variable within multiple queries.
Like the code I highlighted in bold now becomes invalid. So I either have to use prepared statements and repeat the same stuff multiple times in different queries or I can abandon that and I cannot reference variables anymore?
AND ( {{ selectLevels.value.length === 0 }}
OR "Level" = ANY({{ selectLevels.value }}::text)
)
AND mode = 'real'
AND (banned IS NULL OR banned = 0)
Unfortunately that is the tradeoff with prepared statements and dynamic references with {{}} in Retool.
My best suggestion is to keep prepared statements on if you are needing variables from your app. Then just copy/pasting in the SQL WHERE+AND block that you highlighted in green.
It would be nice to store all of that in a variable, but the SQL editor in the query currently is unable to parse that out.
Thank you for the reply Jack. The way we figured this out was that we have been structuring our whole app incorrectly from the very beginning. It is much better and easier to have just one initial huge query and then adjusted with transformers instead of doing different pre-calculated stuff within SQL, which led to us having 5 different queries. Now we have migrated everything to JavaScript, and we do not even have this need to reuse the same query.
Thank you for sharing the advice on the app architecture, that is definitely more complex than what our docs help users with and this information will be very valuable to other users
As sometimes having one large query can be very slow and be a bottleneck but if you found that not to be a limiting factor, you can move the heavy lifting to the browers/Retool app to parse out the data with transformers.