为什么铸造
select cast(st_makepoint(-90.345929, 37.278424) as geography)引发以下错误:
SQL编译错误:参数“TO_GEOGRAPHY”的无效类型强制转换(TO_DOUBLE(-90.345929),TO_DOUBLE(37.278424))
而看似更直接地将st_makepoint结果传递给to_geography的结果不是吗?
select to_geography(st_makepoint(-90.345929, 37.278424))我相当肯定,我被我正在使用的dbt工具中的选角行为所困扰。基本上,我试图将一组表与这个geography字段合并,在编译后的SQL中,这个转换逻辑显示为dbt的union_relations宏的函数,而且我似乎无法控制转换是否发生。
发布于 2022-11-09 18:20:48
union_relations的来源是这里。
您可以将这个宏复制到您自己的项目中(在macros目录下)并对源代码进行修补,然后使用union_relations而不是dbt_utils.union_relations调用它。
违规线路为106-113条。像这样的东西应该能正常工作:
{% for col_name in ordered_column_names -%}
{%- set col = column_superset[col_name] %}
{%- set col_type = column_override.get(col.column, col.data_type) %}
{%- set col_name = adapter.quote(col_name) if col_name in relation_columns[relation] else 'null' %}
{% if col_type == 'geography' %}
to_geography({{ col_name }}) as {{ col.quoted }}
{% else %}
cast({{ col_name }} as {{ col_type }}) as {{ col.quoted }}
{% endif %}
{%- if not loop.last %},{% endif -%}
{%- endfor %}发布于 2022-11-09 17:41:46
因为强制转换不支持源数据类型和目标数据类型的特定组合
https://stackoverflow.com/questions/74378767
复制相似问题