Convert PostgreSQL/Greenplum/Netezza DDL to dbt models compatible with Snowflake. This skill should be used when converting views, tables, or stored procedures from PostgreSQL, Greenplum, or Netezza to dbt code, generating schema.yml files with tests and documentation, or migrating PostgreSQL SQL to follow dbt best practices.
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:
- Run SnowConvert AI on the source DDL to produce Snowflake-compatible SQL.
- Use the
$dbt-migration-snowflakeskill to convert the SCAI output to dbt models.- 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-migrationskill 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_visitsbecomespatient_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 |
| 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 and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
npx skills add sfc-gh-dflippo/dbt-migration-postgres下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer