Teradata to dbt Model Conversion
Purpose
Transform Teradata DDL (views, tables, stored procedures) into production-quality dbt models
compatible with Snowflake, maintaining the same business logic and data transformation steps while
following dbt best practices.
When to Use This Skill
Activate this skill when users ask about:
- Converting Teradata views or tables to dbt models
- Migrating Teradata stored procedures to dbt
- Translating Teradata SQL syntax to Snowflake
- Generating schema.yml files with tests and documentation
- Handling Teradata-specific syntax (QUALIFY, ANSI/TERA modes, volatile tables, DBC views)
Task Description
You are a database engineer working for a hospital system. You need to convert Teradata DDL to
equivalent dbt code compatible with Snowflake, maintaining the same business logic and data
transformation steps while following dbt best practices.
Input Requirements
I will provide you the Teradata DDL to convert.
Audience
The code will be executed by data engineers who are learning Snowflake and dbt.
Output Requirements
Generate the following:
- One or more dbt models with complete SQL for every column
- A corresponding schema.yml file with appropriate tests and documentation
- A config block with materialization strategy
- Explanation of key changes and architectural decisions
- Inline comments highlighting any syntax that was converted
Conversion Guidelines
General Principles
- Replace procedural logic with declarative SQL where possible
- Break down complex procedures into multiple modular dbt models
- Implement appropriate incremental processing strategies
- Maintain data quality checks through dbt tests
- Use Snowflake SQL functions rather than macros whenever possible
Sample Response Format
-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
{{ config(materialized='view') }}
/* Original Object: [database].[table_name]
Source Platform: Teradata
Purpose: [brief description]
Conversion Notes: [key changes]
Description: [SQL logic description] */
WITH source_data AS (
SELECT
customer_id::INTEGER AS customer_id,
customer_name::VARCHAR(100) AS customer_name,
account_balance::NUMBER(18,2) AS account_balance,
created_date::DATE AS created_date
FROM {{ ref('upstream_model') }}
),
transformed_data AS (
SELECT
customer_id,
UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,
account_balance,
created_date,
CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at
FROM source_data
)
SELECT
customer_id,
customer_name_upper,
account_balance,
created_date,
loaded_at
FROM transformed_data
## models/[domain]/[target_schema_name]/_models.yml
version: 2
models:
- name: model_name
description: "Table description; converted from Teradata [Original object name]"
columns:
- name: customer_id
description: "Primary key - unique customer identifier"
tests:
- unique
- not_null
- name: customer_name_upper
description: "Customer name in uppercase"
- name: account_balance
description: "Current account balance; Foreign key to OTHER_TABLE"
tests:
- relationships:
to: ref('OTHER_TABLE')
field: OTHER_TABLE_KEY
- name: created_date
description: "Date the customer record was created"
- name: loaded_at
description: "Timestamp when the record was loaded by dbt"
## dbt_project.yml (excerpt)
models:
my_project:
+materialized: view
domain_name:
+schema: target_schema_name
Specific Translation Rules
dbt Specific Requirements
- If the source is a view, use a view materialization in dbt
- Include appropriate dbt model configuration (materialization type)
- Add documentation blocks for a schema.yml
- Add descriptions for tables and columns
- Include relevant tests
- Define primary keys and relationships
- Assume that upstream objects are models
- Comprehensively provide all the columns in the output
- Break complex procedures into multiple models if needed
- Implement appropriate incremental strategies for large tables
- Use Snowflake SQL functions rather than macros whenever possible
- Always cast columns with explicit precision/scale using
::TYPE syntax (e.g.,
column_name::VARCHAR(100), amount::NUMBER(18,2)) to ensure output matches expected data types
- Always provide explicit column aliases for clarity and documentation
Performance Optimization
- Suggest clustering keys if needed
- Recommend materialization strategy (view vs table)
- Identify potential performance improvements
Teradata to Snowflake Syntax Conversion
- Convert Teradata-specific functions to Snowflake equivalents
- Adjust date/timestamp functions
- Handle data type mappings
- Convert QUALIFY/ROW_NUMBER syntax if present
- Address any volatile table references
- Replace SET/MULTISET table specifications
- Convert ANSI vs TERA session mode syntax
- Handle DBC view equivalents
- Add inline SQL comments highlighting any syntax that was converted
Key Data Type Mappings
| Teradata |
Snowflake |
Notes |
| BIGINT/INTEGER/SMALLINT |
NUMBER(38,0) |
All integers map to NUMBER |
| BYTEINT |
BYTEINT |
|
| DECIMAL/NUMBER |
NUMBER |
|
| FLOAT/REAL |
FLOAT |
|
| CHAR/VARCHAR |
CHAR/VARCHAR |
|
| DATE |
DATE |
|
| TIME/TIMESTAMP |
TIME/TIMESTAMP |
|
| TIMESTAMP WITH TIME ZONE |
TIMESTAMP_TZ |
|
| BLOB |
BINARY |
Limited to 8MB |
| CLOB |
VARCHAR |
Limited to 16MB |
| JSON/XML |
VARIANT |
|
| INTERVAL types |
VARCHAR |
Store as string, use in arithmetic |
| PERIOD types |
VARCHAR |
Store as 'start*end' format |
| ST_GEOMETRY |
GEOGRAPHY |
|
Key Syntax Conversions
-- QUALIFY (Teradata) → Same in Snowflake (natively supported)
SELECT * FROM table QUALIFY ROW_NUMBER() OVER (PARTITION BY col ORDER BY col2) = 1
-- Volatile tables → Temporary tables
CREATE VOLATILE TABLE temp_data AS ... → CREATE TEMPORARY TABLE temp_data AS ...
-- SET/MULTISET → Remove (Snowflake handles duplicates differently)
CREATE SET TABLE → CREATE TABLE
CREATE MULTISET TABLE → CREATE TABLE
-- FALLBACK/JOURNAL → Remove (Snowflake-managed)
NO FALLBACK, NO JOURNAL → (remove entirely)
-- FORMAT in column definition → Remove
DATE FORMAT 'YYYY-MM-DD' → DATE
-- CASESPECIFIC → Remove (use COLLATE if needed)
VARCHAR(100) NOT CASESPECIFIC → VARCHAR(100)
Common Function Mappings
| Teradata |
Snowflake |
Notes |
NVL(a, b) |
NVL(a, b) or COALESCE(a, b) |
Same |
NULLIFZERO(col) |
NULLIF(col, 0) |
|
ZEROIFNULL(col) |
NVL(col, 0) |
|
COALESCE(...) |
COALESCE(...) |
Same |
TRIM(col) |
TRIM(col) |
Remove RTRIM for trailing spaces |
SUBSTR(s, pos, len) |
SUBSTR(s, pos, len) |
Same |
INDEX(str, search) |
POSITION(search IN str) |
|
ADD_MONTHS(d, n) |
DATEADD('month', n, d) |
|
TRUNC(d) |
DATE_TRUNC('day', d) |
|
EXTRACT(part FROM d) |
EXTRACT(part FROM d) |
Same |
DATE '2024-01-15' |
DATE '2024-01-15' |
Same |
CAST(x AS FORMAT 'Y4') |
TO_CHAR(x, 'YYYY') |
|
CASE_N(cond1, cond2) |
CASE WHEN cond1 THEN 1 WHEN cond2 THEN 2 ... END |
|
HASHROW(cols) |
HASH(cols) |
|
RANDOM(low, high) |
UNIFORM(low, high, RANDOM()) |
|
Dependencies
- List any upstream dependencies
- Suggest model organization in dbt project
Validation Checklist
- [] Every DDL statement has been accounted for in the dbt models
- [] SQL in models is compatible with Snowflake
- [] Teradata-specific syntax converted (QUALIFY, SET/MULTISET, volatile tables, DBC)
- [] All business logic preserved
- [] All columns included in output
- [] Data types correctly mapped
- [] Functions translated to Snowflake equivalents
- [] Materialization strategy selected
- [] Tests added
- [] SQL logic description complete
- [] Table descriptions added
- [] Column descriptions added
- [] Dependencies correctly mapped
- [] Incremental logic (if applicable) verified
- [] Inline comments added for converted syntax
Related Skills
- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,
testing, deployment)
- $dbt-modeling - For CTE patterns and SQL structure guidance
- $dbt-testing - For implementing comprehensive dbt tests
- $dbt-architecture - For project organization and folder structure
- $dbt-materializations - For choosing materialization strategies (view, table, incremental,
snapshots)
- $dbt-performance - For clustering keys, warehouse sizing, and query optimization
- $dbt-commands - For running dbt commands and model selection syntax
- $dbt-core - For dbt installation, configuration, and package management
- $snowflake-cli - For executing SQL and managing Snowflake objects
Supported Source Database
| Database |
Key Considerations |
| Teradata |
QUALIFY, ANSI/TERA session modes, volatile tables, SET/MULTISET, BTEQ/FastLoad/MultiLoad scripts, DBC views |
Translation References
Detailed syntax translation guides are available in the translation-references/ folder.
Copyright Notice: The translation reference documentation in this repository is derived from
Snowflake SnowConvert Documentation
and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
Reference Index
- BTEQ Translation
- Data Migration Considerations
- ETL BI Repointing Power BI Teradata Repointing
- Fastload Translation
- Helpers For Procedures
- Multiload Translation
- Power BI Repointing
- Overview (README)
- Scripts To Python BTEQ Translation
- Scripts To Python Snowconvert Script Helpers
- Scripts To Python TPT Translation
- Scripts To Snowflake SQL Translation Reference BTEQ
- Scripts To Snowflake SQL Translation Reference Common Statements
- Scripts To Snowflake SQL Translation Reference Mload
- Session Modes
- Snowconvert Script Helpers
- SQL Translation Reference Analytic
- SQL Translation Reference Data Types
- SQL Translation Reference Database DBC
- SQL Translation Reference DDL Teradata
- SQL Translation Reference DML Teradata
- SQL Translation Reference Iceberg Tables Transformations
- SQL Translation Reference Teradata Built In Functions
- Subqueries
- To Javascript Translation Reference
- To Snowflake Scripting Translation Reference
- TPT Translation
1---2name: dbt-migration-teradata3description: Convert Teradata DDL to dbt models compatible with Snowflake. This skill should be used when converting views, tables, or stored procedures from Teradata to dbt code, generating schema.yml files with tests and documentation, or migrating Teradata SQL to follow dbt best practices.4---5
6# Teradata to dbt Model Conversion
7
8## Purpose
9
10Transform Teradata DDL (views, tables, stored procedures) into production-quality dbt models
11compatible with Snowflake, maintaining the same business logic and data transformation steps while
12following dbt best practices.
13
14## When to Use This Skill
15
16Activate this skill when users ask about:
17
18- Converting Teradata views or tables to dbt models
19- Migrating Teradata stored procedures to dbt
20- Translating Teradata SQL syntax to Snowflake
21- Generating schema.yml files with tests and documentation
22- Handling Teradata-specific syntax (QUALIFY, ANSI/TERA modes, volatile tables, DBC views)
23
24---
25
26## Task Description
27
28You are a database engineer working for a hospital system. You need to convert Teradata DDL to
29equivalent dbt code compatible with Snowflake, maintaining the same business logic and data
30transformation steps while following dbt best practices.
31
32## Input Requirements
33
34I will provide you the Teradata DDL to convert.
35
36## Audience
37
38The code will be executed by data engineers who are learning Snowflake and dbt.
39
40## Output Requirements
41
42Generate the following:
43
441. One or more dbt models with complete SQL for every column
452. A corresponding schema.yml file with appropriate tests and documentation
463. A config block with materialization strategy
474. Explanation of key changes and architectural decisions
485. Inline comments highlighting any syntax that was converted
49
50## Conversion Guidelines
51
52### General Principles
53
54- Replace procedural logic with declarative SQL where possible
55- Break down complex procedures into multiple modular dbt models
56- Implement appropriate incremental processing strategies
57- Maintain data quality checks through dbt tests
58- Use Snowflake SQL functions rather than macros whenever possible
59
60### Sample Response Format
61
62```sql
63-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
64{{ config(materialized='view') }}
65
66/* Original Object: [database].[table_name]
67 Source Platform: Teradata
68 Purpose: [brief description]
69 Conversion Notes: [key changes]
70 Description: [SQL logic description] */
71
72WITH source_data AS (
73 SELECT
74 customer_id::INTEGER AS customer_id,
75 customer_name::VARCHAR(100) AS customer_name,
76 account_balance::NUMBER(18,2) AS account_balance,
77 created_date::DATE AS created_date
78 FROM {{ ref('upstream_model') }}
79),
80
81transformed_data AS (
82 SELECT
83 customer_id,
84 UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,
85 account_balance,
86 created_date,
87 CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at
88 FROM source_data
89)
90
91SELECT
92 customer_id,
93 customer_name_upper,
94 account_balance,
95 created_date,
96 loaded_at
97FROM transformed_data
98```
99
100```yaml
101## models/[domain]/[target_schema_name]/_models.yml
102version: 2
103
104models:
105 - name: model_name
106 description: "Table description; converted from Teradata [Original object name]"
107 columns:
108 - name: customer_id
109 description: "Primary key - unique customer identifier"
110 tests:
111 - unique
112 - not_null
113 - name: customer_name_upper
114 description: "Customer name in uppercase"
115 - name: account_balance
116 description: "Current account balance; Foreign key to OTHER_TABLE"
117 tests:
118 - relationships:
119 to: ref('OTHER_TABLE')
120 field: OTHER_TABLE_KEY
121 - name: created_date
122 description: "Date the customer record was created"
123 - name: loaded_at
124 description: "Timestamp when the record was loaded by dbt"
125```
126
127```yaml
128## dbt_project.yml (excerpt)
129models:
130 my_project:
131 +materialized: view
132 domain_name:
133 +schema: target_schema_name
134```
135
136### Specific Translation Rules
137
138#### dbt Specific Requirements
139
140- If the source is a view, use a view materialization in dbt
141- Include appropriate dbt model configuration (materialization type)
142- Add documentation blocks for a schema.yml
143- Add descriptions for tables and columns
144- Include relevant tests
145- Define primary keys and relationships
146- Assume that upstream objects are models
147- Comprehensively provide all the columns in the output
148- Break complex procedures into multiple models if needed
149- Implement appropriate incremental strategies for large tables
150- Use Snowflake SQL functions rather than macros whenever possible
151- **Always cast columns with explicit precision/scale** using `::TYPE` syntax (e.g.,
152 `column_name::VARCHAR(100)`, `amount::NUMBER(18,2)`) to ensure output matches expected data types
153- **Always provide explicit column aliases** for clarity and documentation
154
155#### Performance Optimization
156
157- Suggest clustering keys if needed
158- Recommend materialization strategy (view vs table)
159- Identify potential performance improvements
160
161#### Teradata to Snowflake Syntax Conversion
162
163- Convert Teradata-specific functions to Snowflake equivalents
164- Adjust date/timestamp functions
165- Handle data type mappings
166- Convert QUALIFY/ROW_NUMBER syntax if present
167- Address any volatile table references
168- Replace SET/MULTISET table specifications
169- Convert ANSI vs TERA session mode syntax
170- Handle DBC view equivalents
171- Add inline SQL comments highlighting any syntax that was converted
172
173#### Key Data Type Mappings
174
175| Teradata | Snowflake | Notes |
176| ------------------------ | -------------- | ---------------------------------- |
177| BIGINT/INTEGER/SMALLINT | NUMBER(38,0) | All integers map to NUMBER |
178| BYTEINT | BYTEINT | |
179| DECIMAL/NUMBER | NUMBER | |
180| FLOAT/REAL | FLOAT | |
181| CHAR/VARCHAR | CHAR/VARCHAR | |
182| DATE | DATE | |
183| TIME/TIMESTAMP | TIME/TIMESTAMP | |
184| TIMESTAMP WITH TIME ZONE | TIMESTAMP_TZ | |
185| BLOB | BINARY | Limited to 8MB |
186| CLOB | VARCHAR | Limited to 16MB |
187| JSON/XML | VARIANT | |
188| INTERVAL types | VARCHAR | Store as string, use in arithmetic |
189| PERIOD types | VARCHAR | Store as 'start\*end' format |
190| ST_GEOMETRY | GEOGRAPHY | |
191
192#### Key Syntax Conversions
193
194```sql
195-- QUALIFY (Teradata) → Same in Snowflake (natively supported)
196SELECT * FROM table QUALIFY ROW_NUMBER() OVER (PARTITION BY col ORDER BY col2) = 1
197
198-- Volatile tables → Temporary tables
199CREATE VOLATILE TABLE temp_data AS ... → CREATE TEMPORARY TABLE temp_data AS ...
200
201-- SET/MULTISET → Remove (Snowflake handles duplicates differently)
202CREATE SET TABLE → CREATE TABLE
203CREATE MULTISET TABLE → CREATE TABLE
204
205-- FALLBACK/JOURNAL → Remove (Snowflake-managed)
206NO FALLBACK, NO JOURNAL → (remove entirely)
207
208-- FORMAT in column definition → Remove
209DATE FORMAT 'YYYY-MM-DD' → DATE
210
211-- CASESPECIFIC → Remove (use COLLATE if needed)
212VARCHAR(100) NOT CASESPECIFIC → VARCHAR(100)
213```
214
215#### Common Function Mappings
216
217| Teradata | Snowflake | Notes |
218| ------------------------ | -------------------------------------------------- | -------------------------------- |
219| `NVL(a, b)` | `NVL(a, b)` or `COALESCE(a, b)` | Same |
220| `NULLIFZERO(col)` | `NULLIF(col, 0)` | |
221| `ZEROIFNULL(col)` | `NVL(col, 0)` | |
222| `COALESCE(...)` | `COALESCE(...)` | Same |
223| `TRIM(col)` | `TRIM(col)` | Remove RTRIM for trailing spaces |
224| `SUBSTR(s, pos, len)` | `SUBSTR(s, pos, len)` | Same |
225| `INDEX(str, search)` | `POSITION(search IN str)` | |
226| `ADD_MONTHS(d, n)` | `DATEADD('month', n, d)` | |
227| `TRUNC(d)` | `DATE_TRUNC('day', d)` | |
228| `EXTRACT(part FROM d)` | `EXTRACT(part FROM d)` | Same |
229| `DATE '2024-01-15'` | `DATE '2024-01-15'` | Same |
230| `CAST(x AS FORMAT 'Y4')` | `TO_CHAR(x, 'YYYY')` | |
231| `CASE_N(cond1, cond2)` | `CASE WHEN cond1 THEN 1 WHEN cond2 THEN 2 ... END` | |
232| `HASHROW(cols)` | `HASH(cols)` | |
233| `RANDOM(low, high)` | `UNIFORM(low, high, RANDOM())` | |
234
235#### Dependencies
236
237- List any upstream dependencies
238- Suggest model organization in dbt project
239
240---
241
242## Validation Checklist
243
244- [] Every DDL statement has been accounted for in the dbt models
245- [] SQL in models is compatible with Snowflake
246- [] Teradata-specific syntax converted (QUALIFY, SET/MULTISET, volatile tables, DBC)
247- [] All business logic preserved
248- [] All columns included in output
249- [] Data types correctly mapped
250- [] Functions translated to Snowflake equivalents
251- [] Materialization strategy selected
252- [] Tests added
253- [] SQL logic description complete
254- [] Table descriptions added
255- [] Column descriptions added
256- [] Dependencies correctly mapped
257- [] Incremental logic (if applicable) verified
258- [] Inline comments added for converted syntax
259
260---
261
262## Related Skills
263
264- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,
265 testing, deployment)
266- $dbt-modeling - For CTE patterns and SQL structure guidance
267- $dbt-testing - For implementing comprehensive dbt tests
268- $dbt-architecture - For project organization and folder structure
269- $dbt-materializations - For choosing materialization strategies (view, table, incremental,
270 snapshots)
271- $dbt-performance - For clustering keys, warehouse sizing, and query optimization
272- $dbt-commands - For running dbt commands and model selection syntax
273- $dbt-core - For dbt installation, configuration, and package management
274- $snowflake-cli - For executing SQL and managing Snowflake objects
275
276---
277
278## Supported Source Database
279
280| Database | Key Considerations |
281| ------------ | ----------------------------------------------------------------------------------------------------------- |
282| **Teradata** | QUALIFY, ANSI/TERA session modes, volatile tables, SET/MULTISET, BTEQ/FastLoad/MultiLoad scripts, DBC views |
283
284## Translation References
285
286Detailed syntax translation guides are available in the `translation-references/` folder.
287
288> **Copyright Notice:** The translation reference documentation in this repository is derived from
289> [Snowflake SnowConvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs)
290> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
291
292### Reference Index
293
294- [BTEQ Translation](translation-references/teradata-bteq-translation.md)
295- [Data Migration Considerations](translation-references/teradata-data-migration-considerations.md)
296- [ETL BI Repointing Power BI Teradata Repointing](translation-references/teradata-etl-bi-repointing-power-bi-teradata-repointing.md)
297- [Fastload Translation](translation-references/teradata-fastload-translation.md)
298- [Helpers For Procedures](translation-references/teradata-helpers-for-procedures.md)
299- [Multiload Translation](translation-references/teradata-multiload-translation.md)
300- [Power BI Repointing](translation-references/teradata-power-bi-repointing.md)
301- [Overview (README)](translation-references/teradata-readme.md)
302- [Scripts To Python BTEQ Translation](translation-references/teradata-scripts-to-python-bteq-translation.md)
303- [Scripts To Python Snowconvert Script Helpers](translation-references/teradata-scripts-to-python-snowconvert-script-helpers.md)
304- [Scripts To Python TPT Translation](translation-references/teradata-scripts-to-python-tpt-translation.md)
305- [Scripts To Snowflake SQL Translation Reference BTEQ](translation-references/teradata-scripts-to-snowflake-sql-translation-reference-bteq.md)
306- [Scripts To Snowflake SQL Translation Reference Common Statements](translation-references/teradata-scripts-to-snowflake-sql-translation-reference-common-statements.md)
307- [Scripts To Snowflake SQL Translation Reference Mload](translation-references/teradata-scripts-to-snowflake-sql-translation-reference-mload.md)
308- [Session Modes](translation-references/teradata-session-modes.md)
309- [Snowconvert Script Helpers](translation-references/teradata-snowconvert-script-helpers.md)
310- [SQL Translation Reference Analytic](translation-references/teradata-sql-translation-reference-analytic.md)
311- [SQL Translation Reference Data Types](translation-references/teradata-sql-translation-reference-data-types.md)
312- [SQL Translation Reference Database DBC](translation-references/teradata-sql-translation-reference-database-dbc.md)
313- [SQL Translation Reference DDL Teradata](translation-references/teradata-sql-translation-reference-ddl-teradata.md)
314- [SQL Translation Reference DML Teradata](translation-references/teradata-sql-translation-reference-dml-teradata.md)
315- [SQL Translation Reference Iceberg Tables Transformations](translation-references/teradata-sql-translation-reference-iceberg-tables-transformations.md)
316- [SQL Translation Reference Teradata Built In Functions](translation-references/teradata-sql-translation-reference-teradata-built-in-functions.md)
317- [Subqueries](translation-references/teradata-subqueries.md)
318- [To Javascript Translation Reference](translation-references/teradata-to-javascript-translation-reference.md)
319- [To Snowflake Scripting Translation Reference](translation-references/teradata-to-snowflake-scripting-translation-reference.md)
320- [TPT Translation](translation-references/teradata-tpt-translation.md)