# Macros on columns from aliased tables

**URL:** <https://discourse.getdbt.com/t/macros-on-columns-from-aliased-tables/8290>\
**Category:** Help\
**Tags:** jinja, macros\
**Created:** [May 15, 2023, 2:28pm UTC](https://discourse.getdbt.com/t/macros-on-columns-from-aliased-tables/8290 "2023-05-15T14:28:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robbert](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/robbert/32/2408_2.png) [@robbert](https://discourse.getdbt.com/u/robbert)\
**Post date:** [May 15, 2023, 2:28pm UTC](https://discourse.getdbt.com/t/macros-on-columns-from-aliased-tables/8290/1 "2023-05-15T14:28:26Z")

</div>

I am trying to pass a column from an aliased table to a macro, i.e.

```auto
select {{my_macro(aliased_table.my_column)}} 
from my_table aliased_table

```

It’s the same problem as [Pass column to macro as variable](https://discourse.getdbt.com/t/pass-column-to-macro-as-variable/535) but the solution does not work for me. I’m using the Trino adapter.

- With single quotes, trino tells me  
`TrinoUserError(type=USER_ERROR, name=COLUMN_NOT_FOUND, message="Column 'aliased_table.my_column' cannot be resolved"`
- With double quotes, trino tells me `TrinoUserError(type=USER_ERROR, name=COLUMN_NOT_FOUND, message="Column 'aliased_table.my_column' cannot be resolved"`
- Without quotes, dbt tells me ` 'aliased_table' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".`

My macro looks like this:

```auto
{% macro my_macro(my_column) %}
regexp_replace("{{ my_column }}", '[-./_;,]', ' ')
{% endmacro %}

```

I’ve also tried `adapter.quote(my_column)`, to no avail.  
I’ve also tried

```auto
{% macro my_macro(my_column) %}
{# allow for select aliased tables like a.col1 #}
{% set lst = my_column.split(".") %}
{% set regex_str = "'[-./_;,]'" %}
{% set target_str = "' '" %}
{% if (lst | length) == 2 %} regexp_replace(lst[0].lst[1], {{ regex_str }}, {{ target_str }})
{% else %} regexp_replace("{{ my_column }}", {{ regex_str }}, {{ target_str }})
{% endif %}
{% endmacro %}

```

But that starts to fail when you put in more complex derived columns like when calling

```auto
{{my_macro(coalesce(a.col, b.col))}}

```

Any clue how to resolve this? Is this a limitation of trino interpreting single quotes as literals?

---

<div class="post-metadata">

**Author:** ![robbert](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/robbert/32/2408_2.png) [@robbert](https://discourse.getdbt.com/u/robbert)\
**Post date:** [May 15, 2023, 2:44pm UTC](https://discourse.getdbt.com/t/macros-on-columns-from-aliased-tables/8290/2 "2023-05-15T14:44:48Z")

</div>

> [@robbert](#):
>
> `regexp_replace("{{ my_column }}", '[-./_;,]', ' ')`

Ah stupid me, don’t put quotes in here…  
Solution:  
`regexp_replace({{ my_column }}, '[-./_;,]', ' ')`
