This skill converts PostgreSQL/Greenplum/Netezza DDL into dbt models compatible with Snowflake, preserving logic and generating tests and documentation.
npx playbooks add skill sfc-gh-dflippo/snowflake-dbt-demo --skill dbt-migration-postgres
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.
Activate this skill when users ask about:
---
> Do NOT begin manual conversion of tables or views. PostgreSQL has **partial SnowConvert AI
> support** (tables and views only — procedures and functions are NOT supported). Before writing any
> dbt model for a table or view by hand:
>
> 1. Run SnowConvert AI on the source DDL to produce Snowflake-compatible SQL.
> 2. Use the $dbt-migration-snowflake skill to convert the SCAI output to dbt models.
> 3. Only fall back to this skill's manual translation rules for objects SCAI could not convert
> (check the conversion report for EWIs) or for procedures/functions (which require manual
> conversion).
>
> See the $dbt-migration skill for download links and full workflow.
> Preserve original object names. The dbt model filename and model name MUST match the original
> source object name (lowercased, without schema prefix). For example, public.patient_visits
> becomes patient_visits.sql. Do not rename objects during migration unless explicitly requested
> by the user.
---
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.
I will provide you the PostgreSQL DDL to convert.
The code will be executed by data engineers who are learning Snowflake and dbt.
Generate the following:
-- 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
::TYPE syntax (e.g.,column_name::VARCHAR(100), amount::NUMBER(18,2)) to ensure output matches expected data types
| 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 | |
-- 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()
| 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 |
---
---
testing, deployment)
snapshots)
---
| Database | Key Considerations |
| ------------------------------------ | --------------------------------------------------------------------------------------------- |
| PostgreSQL / Greenplum / Netezza | Array expressions (<> ALL, = ANY), CHAR padding differences, psql commands, distribution keys |
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](https://docs.snowflake.com/en/migrations/snowconvert-docs)
> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.