PostgreSQL/Greenplum/Netezza to dbt Model Conversion
Purpose
Transform PostgreSQL/Greenplum/Netezza 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 PostgreSQL/Greenplum/Netezza views or tables to dbt models
- Migrating PostgreSQL stored procedures to dbt
- Translating PostgreSQL syntax to Snowflake
- Generating schema.yml files with tests and documentation
- Handling PostgreSQL-specific syntax conversions (array expressions, CHAR padding, psql commands)
Task Description
You are a database engineer working for a hospital system. You need to convert
PostgreSQL/Greenplum/Netezza 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 PostgreSQL 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: PostgreSQL/Greenplum/Netezza
Purpose: [brief description]
Conversion Notes: [key changes]
Description: [SQL logic description] */
WITH source_data AS (
SELECT
-- SERIAL converted to INTEGER (use IDENTITY in table)
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 PostgreSQL [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
PostgreSQL to Snowflake Syntax Conversion
- Convert array expressions (<> ALL, = ANY) to Snowflake equivalents
- Handle CHAR padding differences
- Replace psql commands with SnowSQL equivalents
- Convert distribution keys (Greenplum) to clustering keys
- Handle string comparison behavior differences
- Convert PL/pgSQL to Snowflake Scripting
- Replace PostgreSQL-specific operators
- Handle SERIAL/BIGSERIAL with IDENTITY
Key Data Type Mappings
| PostgreSQL |
Snowflake |
Notes |
| INTEGER/INT/INT4 |
INTEGER |
|
| BIGINT/INT8 |
BIGINT |
|
| SMALLINT/INT2 |
SMALLINT |
|
| SERIAL/BIGSERIAL |
IDENTITY |
Use AUTOINCREMENT |
| NUMERIC/DECIMAL |
NUMERIC |
|
| REAL/FLOAT4 |
FLOAT |
|
| DOUBLE PRECISION/FLOAT8 |
FLOAT |
|
| BOOLEAN/BOOL |
BOOLEAN |
|
| CHAR/VARCHAR/TEXT |
Same |
|
| BYTEA |
BINARY |
|
| DATE |
DATE |
|
| TIME/TIMETZ |
TIME |
Time zone not supported |
| TIMESTAMP/TIMESTAMPTZ |
TIMESTAMP/TIMESTAMP_TZ |
|
| INTERVAL |
VARCHAR |
|
| JSON/JSONB |
VARIANT |
|
| ARRAY |
ARRAY |
|
| UUID |
VARCHAR |
|
Key Syntax Conversions
-- SERIAL -> AUTOINCREMENT
id SERIAL PRIMARY KEY -> id INT AUTOINCREMENT PRIMARY KEY
-- Array expressions
col <> ALL(ARRAY[1,2,3]) -> NOT ARRAY_CONTAINS(col, ARRAY_CONSTRUCT(1,2,3))
col = ANY(ARRAY[1,2,3]) -> ARRAY_CONTAINS(col, ARRAY_CONSTRUCT(1,2,3))
-- psql commands -> SnowSQL
\d table -> DESCRIBE TABLE table
\dt -> SHOW TABLES
-- generate_series -> TABLE(GENERATOR())
generate_series(1, 10) -> TABLE(GENERATOR(ROWCOUNT => 10))
-- NOW() -> CURRENT_TIMESTAMP
NOW() -> CURRENT_TIMESTAMP()
Common Function Mappings
| PostgreSQL |
Snowflake |
Notes |
COALESCE(...) |
COALESCE(...) |
Same |
NULLIF(a, b) |
NULLIF(a, b) |
Same |
NOW() |
CURRENT_TIMESTAMP() |
|
CURRENT_DATE |
CURRENT_DATE() |
Add parentheses |
CURRENT_TIMESTAMP |
CURRENT_TIMESTAMP() |
Add parentheses |
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 |
TO_DATE(s, fmt) |
TO_DATE(s, fmt) |
Same |
TO_NUMBER(s, fmt) |
TO_NUMBER(s, fmt) |
Same |
generate_series(a, b) |
TABLE(GENERATOR(ROWCOUNT => b-a+1)) |
|
array_agg(col) |
ARRAY_AGG(col) |
Same |
string_agg(col, delim) |
LISTAGG(col, delim) |
|
SUBSTR(s, pos, len) |
SUBSTR(s, pos, len) |
Same |
POSITION(s IN str) |
POSITION(s IN str) |
Same |
REGEXP_REPLACE(...) |
REGEXP_REPLACE(...) |
Same |
json_extract_path_text() |
JSON_EXTRACT_PATH_TEXT() |
Same |
::type cast |
::type cast |
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
- [] PostgreSQL-specific syntax converted (array expressions, CHAR padding, distribution keys)
- [] 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 |
| PostgreSQL / Greenplum / Netezza |
Array expressions (<> ALL, = ANY), CHAR padding differences, psql commands, distribution keys |
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
- Data Types Netezza Data Types
- Data Types Postgresql Data Types
- Ddls Create Materialized View Greenplum Create Materialized View
- Ddls Create Materialized View Postgresql Create Materialized View
- Ddls Create Table Greenplum Create Table
- Ddls Create Table Netezza Create Table
- Ddls Create Table Postgresql Create Table
- Ddls Postgresql Create View
- ETL BI Repointing Power BI Postgres Repointing
- Overview (README)
- Subqueries
- Built In Functions
- Expressions
- Interactive Terminal
- String Comparison
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: dbt-migration-postgres3description: Transform PostgreSQL/Greenplum/Netezza DDL (views, tables, stored procedures) into Use when this capability is needed.4---56# PostgreSQL/Greenplum/Netezza to dbt Model Conversion78## Purpose910Transform PostgreSQL/Greenplum/Netezza DDL (views, tables, stored procedures) into11production-quality dbt models compatible with Snowflake, maintaining the same business logic and12data transformation steps while following dbt best practices.1314## When to Use This Skill1516Activate this skill when users ask about:1718- Converting PostgreSQL/Greenplum/Netezza views or tables to dbt models19- Migrating PostgreSQL stored procedures to dbt20- Translating PostgreSQL syntax to Snowflake21- Generating schema.yml files with tests and documentation22- Handling PostgreSQL-specific syntax conversions (array expressions, CHAR padding, psql commands)2324---2526## Task Description2728You are a database engineer working for a hospital system. You need to convert29PostgreSQL/Greenplum/Netezza DDL to equivalent dbt code compatible with Snowflake, maintaining the30same business logic and data transformation steps while following dbt best practices.3132## Input Requirements3334I will provide you the PostgreSQL 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: PostgreSQL/Greenplum/Netezza68 Purpose: [brief description]69 Conversion Notes: [key changes]70 Description: [SQL logic description] */7172WITH source_data AS (73 SELECT74 -- SERIAL converted to INTEGER (use IDENTITY in table)75 customer_id::INTEGER AS customer_id,76 customer_name::VARCHAR(100) AS customer_name,77 account_balance::NUMBER(18,2) AS account_balance,78 -- TIMESTAMPTZ converted to TIMESTAMP_TZ79 created_date::TIMESTAMP_TZ AS created_date80 FROM {{ ref('upstream_model') }}81),8283transformed_data AS (84 SELECT85 customer_id,86 UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,87 account_balance,88 created_date,89 CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at90 FROM source_data91)9293SELECT94 customer_id,95 customer_name_upper,96 account_balance,97 created_date,98 loaded_at99FROM transformed_data100```101102```yaml103## models/[domain]/[target_schema_name]/_models.yml104version: 2105106models:107 - name: model_name108 description: "Table description; converted from PostgreSQL [Original object name]"109 columns:110 - name: customer_id111 description: "Primary key - unique customer identifier"112 tests:113 - unique114 - not_null115 - name: customer_name_upper116 description: "Customer name in uppercase"117 - name: account_balance118 description: "Current account balance; Foreign key to OTHER_TABLE"119 tests:120 - relationships:121 to: ref('OTHER_TABLE')122 field: OTHER_TABLE_KEY123 - name: created_date124 description: "Date the customer record was created"125 - name: loaded_at126 description: "Timestamp when the record was loaded by dbt"127```128129```yaml130## dbt_project.yml (excerpt)131models:132 my_project:133 +materialized: view134 domain_name:135 +schema: target_schema_name136```137138### Specific Translation Rules139140#### dbt Specific Requirements141142- If the source is a view, use a view materialization in dbt143- Include appropriate dbt model configuration (materialization type)144- Add documentation blocks for a schema.yml145- Add descriptions for tables and columns146- Include relevant tests147- Define primary keys and relationships148- Assume that upstream objects are models149- Comprehensively provide all the columns in the output150- Break complex procedures into multiple models if needed151- Implement appropriate incremental strategies for large tables152- Use Snowflake SQL functions rather than macros whenever possible153- **Always cast columns with explicit precision/scale** using `::TYPE` syntax (e.g.,154 `column_name::VARCHAR(100)`, `amount::NUMBER(18,2)`) to ensure output matches expected data types155- **Always provide explicit column aliases** for clarity and documentation156157#### Performance Optimization158159- Suggest clustering keys if needed160- Recommend materialization strategy (view vs table)161- Identify potential performance improvements162163#### PostgreSQL to Snowflake Syntax Conversion164165- Convert array expressions (<> ALL, = ANY) to Snowflake equivalents166- Handle CHAR padding differences167- Replace psql commands with SnowSQL equivalents168- Convert distribution keys (Greenplum) to clustering keys169- Handle string comparison behavior differences170- Convert PL/pgSQL to Snowflake Scripting171- Replace PostgreSQL-specific operators172- Handle SERIAL/BIGSERIAL with IDENTITY173174#### Key Data Type Mappings175176| PostgreSQL | Snowflake | Notes |177| ----------------------- | ---------------------- | ----------------------- |178| INTEGER/INT/INT4 | INTEGER | |179| BIGINT/INT8 | BIGINT | |180| SMALLINT/INT2 | SMALLINT | |181| SERIAL/BIGSERIAL | IDENTITY | Use AUTOINCREMENT |182| NUMERIC/DECIMAL | NUMERIC | |183| REAL/FLOAT4 | FLOAT | |184| DOUBLE PRECISION/FLOAT8 | FLOAT | |185| BOOLEAN/BOOL | BOOLEAN | |186| CHAR/VARCHAR/TEXT | Same | |187| BYTEA | BINARY | |188| DATE | DATE | |189| TIME/TIMETZ | TIME | Time zone not supported |190| TIMESTAMP/TIMESTAMPTZ | TIMESTAMP/TIMESTAMP_TZ | |191| INTERVAL | VARCHAR | |192| JSON/JSONB | VARIANT | |193| ARRAY | ARRAY | |194| UUID | VARCHAR | |195196#### Key Syntax Conversions197198```sql199-- SERIAL -> AUTOINCREMENT200id SERIAL PRIMARY KEY -> id INT AUTOINCREMENT PRIMARY KEY201202-- Array expressions203col <> ALL(ARRAY[1,2,3]) -> NOT ARRAY_CONTAINS(col, ARRAY_CONSTRUCT(1,2,3))204col = ANY(ARRAY[1,2,3]) -> ARRAY_CONTAINS(col, ARRAY_CONSTRUCT(1,2,3))205206-- psql commands -> SnowSQL207\d table -> DESCRIBE TABLE table208\dt -> SHOW TABLES209210-- generate_series -> TABLE(GENERATOR())211generate_series(1, 10) -> TABLE(GENERATOR(ROWCOUNT => 10))212213-- NOW() -> CURRENT_TIMESTAMP214NOW() -> CURRENT_TIMESTAMP()215```216217#### Common Function Mappings218219| PostgreSQL | Snowflake | Notes |220| -------------------------- | ------------------------------------- | --------------- |221| `COALESCE(...)` | `COALESCE(...)` | Same |222| `NULLIF(a, b)` | `NULLIF(a, b)` | Same |223| `NOW()` | `CURRENT_TIMESTAMP()` | |224| `CURRENT_DATE` | `CURRENT_DATE()` | Add parentheses |225| `CURRENT_TIMESTAMP` | `CURRENT_TIMESTAMP()` | Add parentheses |226| `DATE_TRUNC(unit, d)` | `DATE_TRUNC(unit, d)` | Same |227| `EXTRACT(part FROM d)` | `EXTRACT(part FROM d)` | Same |228| `TO_CHAR(d, fmt)` | `TO_CHAR(d, fmt)` | Same |229| `TO_DATE(s, fmt)` | `TO_DATE(s, fmt)` | Same |230| `TO_NUMBER(s, fmt)` | `TO_NUMBER(s, fmt)` | Same |231| `generate_series(a, b)` | `TABLE(GENERATOR(ROWCOUNT => b-a+1))` | |232| `array_agg(col)` | `ARRAY_AGG(col)` | Same |233| `string_agg(col, delim)` | `LISTAGG(col, delim)` | |234| `SUBSTR(s, pos, len)` | `SUBSTR(s, pos, len)` | Same |235| `POSITION(s IN str)` | `POSITION(s IN str)` | Same |236| `REGEXP_REPLACE(...)` | `REGEXP_REPLACE(...)` | Same |237| `json_extract_path_text()` | `JSON_EXTRACT_PATH_TEXT()` | Same |238| `::type` cast | `::type` cast | Same |239240#### Dependencies241242- List any upstream dependencies243- Suggest model organization in dbt project244245---246247## Validation Checklist248249- [] Every DDL statement has been accounted for in the dbt models250- [] SQL in models is compatible with Snowflake251- [] PostgreSQL-specific syntax converted (array expressions, CHAR padding, distribution keys)252- [] All business logic preserved253- [] All columns included in output254- [] Data types correctly mapped255- [] Functions translated to Snowflake equivalents256- [] Materialization strategy selected257- [] Tests added258- [] SQL logic description complete259- [] Table descriptions added260- [] Column descriptions added261- [] Dependencies correctly mapped262- [] Incremental logic (if applicable) verified263- [] Inline comments added for converted syntax264265---266267## Related Skills268269- $dbt-migration - For the complete migration workflow (discovery, planning, placeholder models,270 testing, deployment)271- $dbt-modeling - For CTE patterns and SQL structure guidance272- $dbt-testing - For implementing comprehensive dbt tests273- $dbt-architecture - For project organization and folder structure274- $dbt-materializations - For choosing materialization strategies (view, table, incremental,275 snapshots)276- $dbt-performance - For clustering keys, warehouse sizing, and query optimization277- $dbt-commands - For running dbt commands and model selection syntax278- $dbt-core - For dbt installation, configuration, and package management279- $snowflake-cli - For executing SQL and managing Snowflake objects280281---282283## Supported Source Database284285| Database | Key Considerations |286| ------------------------------------ | --------------------------------------------------------------------------------------------- |287| **PostgreSQL / Greenplum / Netezza** | Array expressions (<> ALL, = ANY), CHAR padding differences, psql commands, distribution keys |288289## Translation References290291Detailed syntax translation guides are available in the `translation-references/` folder.292293> **Copyright Notice:** The translation reference documentation in this repository is derived from294> [Snowflake SnowConvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs)295> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.296297### Reference Index298299- [Data Types Netezza Data Types](translation-references/postgres-data-types-netezza-data-types.md)300- [Data Types Postgresql Data Types](translation-references/postgres-data-types-postgresql-data-types.md)301- [Ddls Create Materialized View Greenplum Create Materialized View](translation-references/postgres-ddls-create-materialized-view-greenplum-create-materialized-view.md)302- [Ddls Create Materialized View Postgresql Create Materialized View](translation-references/postgres-ddls-create-materialized-view-postgresql-create-materialized-view.md)303- [Ddls Create Table Greenplum Create Table](translation-references/postgres-ddls-create-table-greenplum-create-table.md)304- [Ddls Create Table Netezza Create Table](translation-references/postgres-ddls-create-table-netezza-create-table.md)305- [Ddls Create Table Postgresql Create Table](translation-references/postgres-ddls-create-table-postgresql-create-table.md)306- [Ddls Postgresql Create View](translation-references/postgres-ddls-postgresql-create-view.md)307- [ETL BI Repointing Power BI Postgres Repointing](translation-references/postgres-etl-bi-repointing-power-bi-postgres-repointing.md)308- [Overview (README)](translation-references/postgres-readme.md)309- [Subqueries](translation-references/postgres-subqueries.md)310- [Built In Functions](translation-references/postgresql-built-in-functions.md)311- [Expressions](translation-references/postgresql-expressions.md)312- [Interactive Terminal](translation-references/postgresql-interactive-terminal.md)313- [String Comparison](translation-references/postgresql-string-comparison.md)314315---316> Converted and distributed by [TomeVault](https://tomevault.io/claim/sfc-gh-dflippo) — claim your Tome and manage your conversions.317<!-- tomevault:4.0:skill_md:2026-04-11 -->