Our workaround for dynamic queries has been to rely on db_map to give us the partial queries mapped from the proper query file for the RDBMS in question. But you still must put the Tcl var reference in the query, which is sort of ugly. In the case of PG large object emulation you actually have to put a code snippet in the query, which is even uglier but fortunately is restricted to a handful of places.
I'm reasonably satisfied with how we're handling it now even though it would be nice to find a solution that removes Tcl stuff from queryfiles altogether. Among other things we could then drop the "subst" call we do on every query before executing it.