A self-explanatory macro for prefixing all columns.
{%- macro prefix_columns(ref, prefix) -%}
-- prefixes all columns in ref
{%- set cols = adapter.get_columns_in_relation(ref) -%}
-- select all columns from ref1
select
{% for col in cols %}
{% if not loop.last %}
table1.{{col.name}} as {{prefix}}{{col.name}},
{% else %}
table1.{{col.name}} as {{prefix}}{{col.name}}
{% endif %}
{% endfor %}
from
{{ ref }} as table1
{%- endmacro -%}