I know you can't dynamically set your table when it comes to the query builer. I know this because it has to do with the way PDO, the underlying SQL driver, works under the hood - it doesn't accept these dynamic values...
However, you are Retool, after all, so I am sure you can make it work. How? Well, in the UI variant of the query builder, you can filter against the given list of existing resources (i.e. tables/views, whatnot) and then based on that allow or disallow a certain value.
I realize this may give the user the impression anything goes, so it's important to communicate that the dynamic value can be added, but only when it is actually a valid table. Otherwise it will get rejected.
I think this could allow for some DRY'ing up of your UIs, which I've found to be the most tedious and energy-consuming task.
Thanks for taking this into consideration!