column1 ^^ column2 ^^ ...
我想使用DBT for Redshift 中的语法连接几列。如果列中存在 NULL 值,@@
则应使用 fe @@ ^^ @@
。我找到了以下用于连接的宏:
{% macro safe_concat(field_list) %}
{# Takes an input list and generates a concat() statement with each argument in the list safe_casted to a string and wrapped in an ifnull() #}
concat({% for f in field_list %}
ifnull(safe_cast({{ f }} as string), '@@')
{% if not loop.last %}, {% endif %}
{% endfor %})
{% endmacro %}
当我在我的选择语句中使用它时:
select
{{ safe_concat([street, city]) }} as address_key
from source
我收到以下错误。这与我正在使用的代码有关吗?
Database Error in model address (models/address.sql)
syntax error at or near "as"
LINE 32: ifnull(safe_cast( as string), '@@')