However, my question is: Is there a way to implement it in a way that does not depend on the remote data structure?
Is there a way to get rid of the AS without having to define a type?
Unfortunately, no. The parse and planning stages need defined types, so waiting for the function to execute is too late. We've discussed it a time or two before (as recently as within the last week), but the conclusion has been that there is no easy answer to the problem.
Joe
---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match