You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want to query the columns of a relation the macro below does not contain the database but an empty pair of square brackets, which does not work for me.
with mapping as (
select
row_number() over (partition by object_name(c.object_id) order by c.column_id) as ordinal_position,
c.name collate database_default as column_name,
t.name as data_type,
c.max_length as character_maximum_length,
c.precision as numeric_precision,
c.scale as numeric_scale
from [{{ 'tempdb' if '#' in relation.identifier else relation.database }}].sys.columns c {{ information_schema_hints() }}
inner join sys.types t {{ information_schema_hints() }}
on c.user_type_id = t.user_type_id
where c.object_id = object_id('{{ 'tempdb..' ~ relation.include(database=false, schema=false) if '#' in relation.identifier else relation }}')
)
select
column_name,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
from mapping
order by ordinal_position
{{ query_label }}
{% endcall %}
{% set table = load_result('get_columns_in_relation').table %}
{{ return(sql_convert_columns_in_relation(table)) }}
{% endmacro %}
If I omit the square brackets, the macro works for the use case, where I want to get all the columns of a specific object.
The text was updated successfully, but these errors were encountered:
with mapping as (
select
row_number() over (partition by object_name(c.object_id) order by c.column_id) as ordinal_position,
c.name collate database_default as column_name,
t.name as data_type,
c.max_length as character_maximum_length,
c.precision as numeric_precision,
c.scale as numeric_scale
from {{ 'tempdb' if '#' in relation.identifier else '[' ~ relation.database ~ ']' if relation.database != is_null else '' }}.sys.columns c {{ information_schema_hints() }}
inner join sys.types t {{ information_schema_hints() }}
on c.user_type_id = t.user_type_id
where c.object_id = object_id('{{ 'tempdb..' ~ relation.include(database=false, schema=false) if '#' in relation.identifier else relation }}')
)
select
column_name,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
from mapping
order by ordinal_position
{{ query_label }}
{% endcall %}
{% set table = load_result('get_columns_in_relation').table %}
{{ return(sql_convert_columns_in_relation(table)) }}
If I want to query the columns of a relation the macro below does not contain the database but an empty pair of square brackets, which does not work for me.
original macro:
{% macro fabric__get_columns_in_relation(relation) -%}
{% set query_label = apply_label() %}
{% call statement('get_columns_in_relation', fetch_result=True) %}
{% endmacro %}
If I omit the square brackets, the macro works for the use case, where I want to get all the columns of a specific object.
The text was updated successfully, but these errors were encountered: