How to remove a comma ?

I’m a bit lost
In my macros, I would like to get the name of a column and use the name of this column in an other macro.
I tried a lot of things, but I didn’t really succeed.
At the moment I’m using a call statement in my macro, but I can’t seem to remove the comma after the ‘day’…
Does anyone have an idea?

I have already tried [‘data’][0] but I encountered an error :

Compilation Error in model Test (models\Monitoring\Test.sql)
‘None’ has no attribute ‘data’

in macro obtain_date (macros\obtain_date.sql)
called by model Test (models\Monitoring\Test.sql)

Can you post the actual code inside of backticks? It’s hard to read a screenshot

Here is my macro

{% macro obtain_date() %}

{%- call statement('Column_name_date', fetch_result=True) -%}

SELECT column_name
WHERE table_name = 'A_sales_dailySiteFamily' AND (column_name LIKE 'day%' or column_name like 'week%' or column_name like 'month%')

{% endcall %}

{%- set column_name_date1 = load_result('Column_name_date')['data'] -%}


{% endmacro %} 

Here is my model

SELECT {{obtain_date()}} 
FROM {{sources('SALES', 'A_sales_dailySiteFamily')}}

And when I compile I have :

SELECT [('day',)]
FROM blablabla 

Do you know how to remove the comma after the ‘day’ ?

I assume that the return type of load_result isn’t just a simple string, but I’m not sure exactly what it is. I’m on mobile so not able to dig into this deeply, but if your use case is to get specific columns then you can go about it a different way.

Try using dbt_utils’ get_filtered_columns_in_relation or the native adapter.get_columns_in_relation, then you can filter the names of the columns based on the results of that.


I am also getting the similar error. Is it resolved?

{%- set results = run_query(sql).columns[0].values() -%} – results into the comma separated values perfectly when there are multiple values to return e.g. (‘a’,‘b’,‘c’)
but it returns (‘a’,) when sql fetches only one value.