Amazon Redshift to dbt Model Conversion
Purpose
Transform Amazon Redshift 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 Redshift views or tables to dbt models
- Migrating Redshift PL/pgSQL stored procedures to dbt
- Translating Redshift SQL syntax to Snowflake
- Generating schema.yml files with tests and documentation
- Handling Redshift-specific syntax (DISTKEY/SORTKEY, system catalogs, COPY/UNLOAD)
Task Description
You are a database engineer working for a hospital system. You need to convert Amazon Redshift 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 Redshift 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].[schema].[object_name]
Source Platform: Amazon Redshift
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,
-- TIMESTAMPTZ converted to TIMESTAMP_TZ
created_date::TIMESTAMP_TZ 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 Amazon Redshift [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
Redshift to Snowflake Syntax Conversion
- Remove DISTKEY/SORTKEY specifications (use clustering keys instead)
- Convert system catalog queries (pg**, stl*_, stv__) to Snowflake equivalents
- Replace COPY/UNLOAD with Snowflake COPY INTO
- Convert PL/pgSQL procedures to Snowflake Scripting
- Handle IDENTITY column differences
- Replace Redshift-specific date functions
- Convert APPROXIMATE COUNT DISTINCT to HLL functions
- Add inline SQL comments highlighting any syntax that was converted
Key Data Type Mappings
| Redshift |
Snowflake |
Notes |
| INT/INT2/INT4/INT8/INTEGER/BIGINT |
Same |
All alias to NUMBER |
| SMALLINT |
SMALLINT |
|
| DECIMAL/NUMERIC |
Same |
|
| FLOAT/FLOAT4/FLOAT8/REAL |
FLOAT |
|
| BOOL/BOOLEAN |
BOOLEAN |
|
| CHAR/VARCHAR/TEXT |
Same |
VARCHAR(MAX) → VARCHAR |
| BPCHAR |
VARCHAR |
|
| BINARY/VARBINARY/VARBYTE |
BINARY |
Max 8MB (vs 16MB Redshift) |
| DATE |
DATE |
|
| TIME/TIMETZ |
TIME |
Time zone not supported |
| TIMESTAMP/TIMESTAMPTZ |
TIMESTAMP/TIMESTAMP_TZ |
|
| INTERVAL types |
VARCHAR |
|
| GEOMETRY/GEOGRAPHY |
Same |
|
| SUPER |
VARIANT |
|
| HLLSKETCH |
Not supported |
Use HLL functions |
Key Syntax Conversions
-- DISTKEY/SORTKEY → Remove (use clustering keys)
CREATE TABLE t (id INT) DISTKEY(id) SORTKEY(created_at) →
CREATE TABLE t (id INT) CLUSTER BY (created_at)
-- COPY/UNLOAD → COPY INTO
COPY table FROM 's3://bucket/path' IAM_ROLE 'arn:...' →
COPY INTO table FROM @stage/path
-- System catalogs
pg_catalog.pg_tables → INFORMATION_SCHEMA.TABLES
stl_query → QUERY_HISTORY table function
stv_sessions → SHOW SESSIONS
-- GETDATE() → CURRENT_TIMESTAMP
GETDATE() → CURRENT_TIMESTAMP()
-- NVL → COALESCE
NVL(col, 0) → COALESCE(col, 0)
-- LISTAGG
LISTAGG(col, ',') WITHIN GROUP (ORDER BY col) →
LISTAGG(col, ',') WITHIN GROUP (ORDER BY col)
-- APPROXIMATE COUNT DISTINCT
APPROXIMATE COUNT(DISTINCT col) → APPROX_COUNT_DISTINCT(col)
Common Function Mappings
| Redshift |
Snowflake |
Notes |
NVL(a, b) |
NVL(a, b) or COALESCE(a, b) |
Same |
NVL2(a, b, c) |
IFF(a IS NOT NULL, b, c) |
|
COALESCE(...) |
COALESCE(...) |
Same |
NULLIF(a, b) |
NULLIF(a, b) |
Same |
GETDATE() |
CURRENT_TIMESTAMP() |
|
SYSDATE |
CURRENT_DATE() |
|
DATEADD(unit, n, d) |
DATEADD(unit, n, d) |
Same |
DATEDIFF(unit, d1, d2) |
DATEDIFF(unit, d1, d2) |
Same |
DATE_TRUNC(unit, d) |
DATE_TRUNC(unit, d) |
Same |
EXTRACT(part FROM d) |
EXTRACT(part FROM d) |
Same |
TO_CHAR(d, fmt) |
TO_CHAR(d, fmt) |
Same |
CONVERT(type, val) |
val::type |
|
LEN(str) |
LENGTH(str) |
|
CHARINDEX(s, str) |
POSITION(s IN str) |
|
LISTAGG(col, delim) |
LISTAGG(col, delim) |
Same |
APPROXIMATE COUNT(DISTINCT) |
APPROX_COUNT_DISTINCT() |
|
JSON_EXTRACT_PATH_TEXT() |
JSON_EXTRACT_PATH_TEXT() |
Same |
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
- [] Redshift-specific syntax converted (DISTKEY/SORTKEY removed, system catalogs mapped)
- [] 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 |
| Amazon Redshift |
DISTKEY/SORTKEY, PL/pgSQL procedures, system catalogs (pg_, stl_, stv_), COPY/UNLOAD |
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
- Basic Elements Literals
- Basic Elements
- Conditions
- Continue Handler
- Create Procedure
- Data Types
- ETL BI Repointing Power BI Redshift Repointing
- Exit Handler
- Expressions
- Functions
- Overview (README)
- Rs SQL Statements Select Into
- Rs SQL Statements Select
- SQL Statements Create Table As
- SQL Statements Create Table
- SQL Statements
- Subqueries
- System Catalog
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: dbt-migration-redshift3description: Transform Amazon Redshift DDL (views, tables, stored procedures) into production-quality dbt models Use when this capability is needed.4---56# Amazon Redshift to dbt Model Conversion78## Purpose910Transform Amazon Redshift DDL (views, tables, stored procedures) into production-quality dbt models11compatible with Snowflake, maintaining the same business logic and data transformation steps while12following dbt best practices.1314## When to Use This Skill1516Activate this skill when users ask about:1718- Converting Redshift views or tables to dbt models19- Migrating Redshift PL/pgSQL stored procedures to dbt20- Translating Redshift SQL syntax to Snowflake21- Generating schema.yml files with tests and documentation22- Handling Redshift-specific syntax (DISTKEY/SORTKEY, system catalogs, COPY/UNLOAD)2324---2526## Task Description2728You are a database engineer working for a hospital system. You need to convert Amazon Redshift DDL29to equivalent dbt code compatible with Snowflake, maintaining the same business logic and data30transformation steps while following dbt best practices.3132## Input Requirements3334I will provide you the Redshift DDL to convert.3536## Audience3738The code will be executed by data engineers who are learning Snowflake and dbt.3940## Output Requirements4142Generate the following:43441. One or more dbt models with complete SQL for every column452. A corresponding schema.yml file with appropriate tests and documentation463. A config block with materialization strategy474. Explanation of key changes and architectural decisions485. Inline comments highlighting any syntax that was converted4950## Conversion Guidelines5152### General Principles5354- Replace procedural logic with declarative SQL where possible55- Break down complex procedures into multiple modular dbt models56- Implement appropriate incremental processing strategies57- Maintain data quality checks through dbt tests58- Use Snowflake SQL functions rather than macros whenever possible5960### Sample Response Format6162```sql63-- dbt model: models/[domain]/[target_schema_name]/model_name.sql64{{ config(materialized='view') }}6566/* Original Object: [database].[schema].[object_name]67 Source Platform: Amazon Redshift68 Purpose: [brief description]69 Conversion Notes: [key changes]70 Description: [SQL logic description] */7172WITH source_data AS (73 SELECT74 customer_id::INTEGER AS customer_id,75 customer_name::VARCHAR(100) AS customer_name,76 account_balance::NUMBER(18,2) AS account_balance,77 -- TIMESTAMPTZ converted to TIMESTAMP_TZ78 created_date::TIMESTAMP_TZ AS created_date79 FROM {{ ref('upstream_model') }}80),8182transformed_data AS (83 SELECT84 customer_id,85 UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,86 account_balance,87 created_date,88 CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at89 FROM source_data90)9192SELECT93 customer_id,94 customer_name_upper,95 account_balance,96 created_date,97 loaded_at98FROM transformed_data99```100101```yaml102## models/[domain]/[target_schema_name]/_models.yml103version: 2104105models:106 - name: model_name107 description: "Table description; converted from Amazon Redshift [Original object name]"108 columns:109 - name: customer_id110 description: "Primary key - unique customer identifier"111 tests:112 - unique113 - not_null114 - name: customer_name_upper115 description: "Customer name in uppercase"116 - name: account_balance117 description: "Current account balance; Foreign key to OTHER_TABLE"118 tests:119 - relationships:120 to: ref('OTHER_TABLE')121 field: OTHER_TABLE_KEY122 - name: created_date123 description: "Date the customer record was created"124 - name: loaded_at125 description: "Timestamp when the record was loaded by dbt"126```127128```yaml129## dbt_project.yml (excerpt)130models:131 my_project:132 +materialized: view133 domain_name:134 +schema: target_schema_name135```136137### Specific Translation Rules138139#### dbt Specific Requirements140141- If the source is a view, use a view materialization in dbt142- Include appropriate dbt model configuration (materialization type)143- Add documentation blocks for a schema.yml144- Add descriptions for tables and columns145- Include relevant tests146- Define primary keys and relationships147- Assume that upstream objects are models148- Comprehensively provide all the columns in the output149- Break complex procedures into multiple models if needed150- Implement appropriate incremental strategies for large tables151- Use Snowflake SQL functions rather than macros whenever possible152- **Always cast columns with explicit precision/scale** using `::TYPE` syntax (e.g.,153 `column_name::VARCHAR(100)`, `amount::NUMBER(18,2)`) to ensure output matches expected data types154- **Always provide explicit column aliases** for clarity and documentation155156#### Performance Optimization157158- Suggest clustering keys if needed159- Recommend materialization strategy (view vs table)160- Identify potential performance improvements161162#### Redshift to Snowflake Syntax Conversion163164- Remove DISTKEY/SORTKEY specifications (use clustering keys instead)165- Convert system catalog queries (pg*\*, stl*\_, stv\_\_) to Snowflake equivalents166- Replace COPY/UNLOAD with Snowflake COPY INTO167- Convert PL/pgSQL procedures to Snowflake Scripting168- Handle IDENTITY column differences169- Replace Redshift-specific date functions170- Convert APPROXIMATE COUNT DISTINCT to HLL functions171- Add inline SQL comments highlighting any syntax that was converted172173#### Key Data Type Mappings174175| Redshift | Snowflake | Notes |176| --------------------------------- | ---------------------- | -------------------------- |177| INT/INT2/INT4/INT8/INTEGER/BIGINT | Same | All alias to NUMBER |178| SMALLINT | SMALLINT | |179| DECIMAL/NUMERIC | Same | |180| FLOAT/FLOAT4/FLOAT8/REAL | FLOAT | |181| BOOL/BOOLEAN | BOOLEAN | |182| CHAR/VARCHAR/TEXT | Same | VARCHAR(MAX) → VARCHAR |183| BPCHAR | VARCHAR | |184| BINARY/VARBINARY/VARBYTE | BINARY | Max 8MB (vs 16MB Redshift) |185| DATE | DATE | |186| TIME/TIMETZ | TIME | Time zone not supported |187| TIMESTAMP/TIMESTAMPTZ | TIMESTAMP/TIMESTAMP_TZ | |188| INTERVAL types | VARCHAR | |189| GEOMETRY/GEOGRAPHY | Same | |190| SUPER | VARIANT | |191| HLLSKETCH | Not supported | Use HLL functions |192193#### Key Syntax Conversions194195```sql196-- DISTKEY/SORTKEY → Remove (use clustering keys)197CREATE TABLE t (id INT) DISTKEY(id) SORTKEY(created_at) →198CREATE TABLE t (id INT) CLUSTER BY (created_at)199200-- COPY/UNLOAD → COPY INTO201COPY table FROM 's3://bucket/path' IAM_ROLE 'arn:...' →202COPY INTO table FROM @stage/path203204-- System catalogs205pg_catalog.pg_tables → INFORMATION_SCHEMA.TABLES206stl_query → QUERY_HISTORY table function207stv_sessions → SHOW SESSIONS208209-- GETDATE() → CURRENT_TIMESTAMP210GETDATE() → CURRENT_TIMESTAMP()211212-- NVL → COALESCE213NVL(col, 0) → COALESCE(col, 0)214215-- LISTAGG216LISTAGG(col, ',') WITHIN GROUP (ORDER BY col) →217LISTAGG(col, ',') WITHIN GROUP (ORDER BY col)218219-- APPROXIMATE COUNT DISTINCT220APPROXIMATE COUNT(DISTINCT col) → APPROX_COUNT_DISTINCT(col)221```222223#### Common Function Mappings224225| Redshift | Snowflake | Notes |226| ----------------------------- | ------------------------------- | ----- |227| `NVL(a, b)` | `NVL(a, b)` or `COALESCE(a, b)` | Same |228| `NVL2(a, b, c)` | `IFF(a IS NOT NULL, b, c)` | |229| `COALESCE(...)` | `COALESCE(...)` | Same |230| `NULLIF(a, b)` | `NULLIF(a, b)` | Same |231| `GETDATE()` | `CURRENT_TIMESTAMP()` | |232| `SYSDATE` | `CURRENT_DATE()` | |233| `DATEADD(unit, n, d)` | `DATEADD(unit, n, d)` | Same |234| `DATEDIFF(unit, d1, d2)` | `DATEDIFF(unit, d1, d2)` | Same |235| `DATE_TRUNC(unit, d)` | `DATE_TRUNC(unit, d)` | Same |236| `EXTRACT(part FROM d)` | `EXTRACT(part FROM d)` | Same |237| `TO_CHAR(d, fmt)` | `TO_CHAR(d, fmt)` | Same |238| `CONVERT(type, val)` | `val::type` | |239| `LEN(str)` | `LENGTH(str)` | |240| `CHARINDEX(s, str)` | `POSITION(s IN str)` | |241| `LISTAGG(col, delim)` | `LISTAGG(col, delim)` | Same |242| `APPROXIMATE COUNT(DISTINCT)` | `APPROX_COUNT_DISTINCT()` | |243| `JSON_EXTRACT_PATH_TEXT()` | `JSON_EXTRACT_PATH_TEXT()` | Same |244245#### Dependencies246247- List any upstream dependencies248- Suggest model organization in dbt project249250---251252## Validation Checklist253254- [] Every DDL statement has been accounted for in the dbt models255- [] SQL in models is compatible with Snowflake256- [] Redshift-specific syntax converted (DISTKEY/SORTKEY removed, system catalogs mapped)257- [] All business logic preserved258- [] All columns included in output259- [] Data types correctly mapped260- [] Functions translated to Snowflake equivalents261- [] Materialization strategy selected262- [] Tests added263- [] SQL logic description complete264- [] Table descriptions added265- [] Column descriptions added266- [] Dependencies correctly mapped267- [] Incremental logic (if applicable) verified268- [] Inline comments added for converted syntax269270---271272## Related Skills273274- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,275 testing, deployment)276- $dbt-modeling - For CTE patterns and SQL structure guidance277- $dbt-testing - For implementing comprehensive dbt tests278- $dbt-architecture - For project organization and folder structure279- $dbt-materializations - For choosing materialization strategies (view, table, incremental,280 snapshots)281- $dbt-performance - For clustering keys, warehouse sizing, and query optimization282- $dbt-commands - For running dbt commands and model selection syntax283- $dbt-core - For dbt installation, configuration, and package management284- $snowflake-cli - For executing SQL and managing Snowflake objects285286---287288## Supported Source Database289290| Database | Key Considerations |291| ------------------- | --------------------------------------------------------------------------------------- |292| **Amazon Redshift** | DISTKEY/SORTKEY, PL/pgSQL procedures, system catalogs (pg\_, stl\_, stv\_), COPY/UNLOAD |293294## Translation References295296Detailed syntax translation guides are available in the `translation-references/` folder.297298> **Copyright Notice:** The translation reference documentation in this repository is derived from299> [Snowflake SnowConvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs)300> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.301302### Reference Index303304- [Basic Elements Literals](translation-references/redshift-basic-elements-literals.md)305- [Basic Elements](translation-references/redshift-basic-elements.md)306- [Conditions](translation-references/redshift-conditions.md)307- [Continue Handler](translation-references/redshift-continue-handler.md)308- [Create Procedure](translation-references/redshift-create-procedure.md)309- [Data Types](translation-references/redshift-data-types.md)310- [ETL BI Repointing Power BI Redshift Repointing](translation-references/redshift-etl-bi-repointing-power-bi-redshift-repointing.md)311- [Exit Handler](translation-references/redshift-exit-handler.md)312- [Expressions](translation-references/redshift-expressions.md)313- [Functions](translation-references/redshift-functions.md)314- [Overview (README)](translation-references/redshift-readme.md)315- [Rs SQL Statements Select Into](translation-references/redshift-rs-sql-statements-select-into.md)316- [Rs SQL Statements Select](translation-references/redshift-rs-sql-statements-select.md)317- [SQL Statements Create Table As](translation-references/redshift-sql-statements-create-table-as.md)318- [SQL Statements Create Table](translation-references/redshift-sql-statements-create-table.md)319- [SQL Statements](translation-references/redshift-sql-statements.md)320- [Subqueries](translation-references/redshift-subqueries.md)321- [System Catalog](translation-references/redshift-system-catalog.md)322323---324> Converted and distributed by [TomeVault](https://tomevault.io/claim/sfc-gh-dflippo) — claim your Tome and manage your conversions.325<!-- tomevault:4.0:skill_md:2026-04-11 -->