get_columns_in_relation macro but using CTE instead of a Relation object

You seem to have the same problem as this tread, I am trying to find a solution, although not very performant most likely. I will post it there.