dbt-sqlserver
dbt-sqlserver copied to clipboard
get_columns_in_relation() returns wrong columns for Temp Relations with the same relation identifier (table) as other schemas
2022-09-15 17:57:11.594602 (Thread-4): On model.mart.DataMart__AzureAD__USERS:
SELECT
column_name,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
FROM
(select
ordinal_position,
column_name,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
from [DataMart].INFORMATION_SCHEMA.COLUMNS
where table_name = '#USERS__dbt_tmp'
and table_schema = 'AzureAD'
UNION ALL
select
ordinal_position,
column_name collate database_default,
data_type collate database_default,
character_maximum_length,
numeric_precision,
numeric_scale
from tempdb.INFORMATION_SCHEMA.COLUMNS
where table_name like '#USERS__dbt_tmp%') cols
order by ordinal_position
This sql comes from https://github.com/dbt-msft/dbt-sqlserver/blob/master/dbt/include/sqlserver/macros/adapters/columns.sql#L27
My issue is that I have a schema AzrueAD with a table Users and another Schema with a table Users so I get columns from the wrong table in the relation.
Ended up being a threading issue as we have multiple queries with a "Users" identifier being run. Lots of potential fixes, easiest I thought was to just give the Temp table a unique name PR is in
fixed in #368