Oleg Levy
08/28/2025, 7:16 AMvisch
08/28/2025, 1:08 PMtarget-postgres do this, but generally we view that as something that should happen after the dataload so we'd recommend using something like dbt to run whatever modifications you want to on the data aftervisch
08/28/2025, 1:10 PMcreate_table macro for mssql for a project that's been running for ~5 years. This is more complicated than you're asking but I think it might show why we don't mess around with this stuff in the target. Note that I also don't do any of the indexes in the raw table I do everything downstream
{% macro sqlserver__create_table_as(temporary, relation, sql) -%}
{%- set as_columnstore = config.get('as_columnstore', default=false) -%}
{%- set as_temporal= config.get('as_temporal', default=false) -%}
{% set unique_key = config.get('unique_key') %}
{% set tmp_relation = relation.incorporate(
path={"identifier": relation.identifier.replace("#", "") ~ '_temp_view'},
type='view')-%}
{%- set temp_view_sql = sql.replace("'", "''") -%}
{{ sqlserver__drop_relation_script(tmp_relation) }}
{{ sqlserver__drop_relation_script(relation) }}
USE [{{ relation.database }}];
EXEC('create view {{ tmp_relation.include(database=False) }} as
{{ temp_view_sql }}
');
SELECT * INTO {{ relation }} FROM
{{ tmp_relation }}
{{ sqlserver__drop_relation_script(tmp_relation) }}
{% if not temporary and as_columnstore -%}
{{ sqlserver__create_clustered_columnstore_index(relation) }}
{% endif %}
{% if unique_key and not as_columnstore -%}
CREATE CLUSTERED INDEX {{ unique_key }} ON {{ relation.schema }}.{{ relation.identifier }} ({{ unique_key }})
ALTER TABLE {{ relation.schema }}.{{ relation.identifier }} add primary key({{ unique_key }})
{% endif %}
{% if as_temporal and not as_columnstore and not temporary -%}
ALTER TABLE {{ relation.schema }}.{{ relation.identifier }}
ADD
RowUpdateStatus varchar( 64 ) default 'Insert' not null
,UpdateUser varchar( 64 ) default system_user not null
,UpdateDateTime datetime2( 7 ) default sysdatetime() not null
,SystemStartDateTime DATETIME2 GENERATED ALWAYS AS ROW START
CONSTRAINT DF_SysStart_{{ relation.identifier }} DEFAULT SYSUTCDATETIME()
,SystemEndDateTime DATETIME2 GENERATED ALWAYS AS ROW END
CONSTRAINT DF_SysEnd_{{ relation.identifier }} DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'),
PERIOD FOR SYSTEM_TIME (SystemStartDateTime, SystemEndDateTime);
ALTER TABLE {{ relation.schema }}.{{ relation.identifier }}
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = {{ relation.schema }}.{{ relation.identifier }}_history));
{% endif %}
{% endmacro %}_
Might help you have anOleg Levy
08/28/2025, 10:15 PMvisch
08/29/2025, 12:53 AMmeltano run tap-oracle target-postgres dbt:something or dbt:runOleg Levy
08/29/2025, 1:51 AMmark_estey
09/02/2025, 2:20 PMmark_estey
09/02/2025, 2:23 PMOleg Levy
09/03/2025, 10:19 PM