Snowflake dbt pitfalls

From CarlosCaPe/octorato · View interactive version

Snowflake dbt pitfalls is an AI agent skill from the GitHub repository CarlosCaPe/octorato. Snowflake and dbt traps that fail silently or destroy data: CREATE OR REPLACE, Dynamic Tables, PIVOT, sources.yml freshness, versioned models. Each one with its prevention.

How to use this skill

Skill file

Snowflake and dbt pitfalls (silent / destructive)

Five non-obvious footguns distilled from real engineering sessions. Each is something the docs underplay and that a future task can trigger on. Generic only.

1. `CREATE OR REPLACE TABLE` resets the new object's Time Travel lineage

CREATE OR REPLACE TABLE drops the old table and creates a new object with fresh lineage. What this breaks:

So the real risk is silent lineage loss and a clumsy recovery, not permanent data loss. Engineers misread it because CREATE OR REPLACE is idiomatic for views/procs/stages. Prevention: CLONE first for a clean, immediately queryable backup with intact history:

CREATE OR REPLACE TABLE my_table_backup CLONE my_table;
CREATE OR REPLACE TABLE my_table AS SELECT ...;

2. Snowflake Dynamic Table (DT) constraints

3. Snowflake `PIVOT` with dotted column values (two compounding bugs)

WITH normalized AS (
  SELECT REPLACE(tag_id, '.', '_') AS tag_id_clean, value FROM source_table
)
SELECT *
FROM normalized
PIVOT(MAX(value) FOR tag_id_clean IN ('c2_tag_avg', 'c3_tag_sum'));
-- IN values stay quoted literals; headers come back as 'c2_tag_avg' etc.
-- add  AS p (grp, c2_tag_avg, c3_tag_sum)  if you need bare SELECTable identifiers

Symptom that points here: PIVOT returns the column-name strings or nulls instead of values.

4. dbt `sources.yml` freshness has two underused keys

Symptom: a freshness check passing when it should fail (or vice versa).

5. dbt versioned-model `include/exclude` placement

In versioned models (versions: in schema.yml), an include: all / exclude: [col] block nested inside the columns: list is structurally invalid and throws a YAML parse error that survives typo fixes (the error is structural, not textual). It belongs at the version level, a sibling of defined_in:/config::

versions:
  - v: 1
    include: all
    exclude: [deprecated_col]
    # NOT under columns:

Symptom: a dbt YAML parse error pointing at the wrong line that persists after every typo fix.

Provenance

Distilled from real Snowflake/dbt debugging sessions, stripped of any project data. Complements querymaster-snowflake (query authoring) and the DDL-safety skills; this one is specifically the silent/destructive gotcha set.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.