duckdb-scd

Implements Slowly Changing Dimensions Type 2 in DuckDB using MERGE INTO statements.

9|Updated Feb 16, 2026
One-click install
npx skills add https://github.com/mathisdrn/orca --skill duckdb-scd-mathisdrn
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: duckdb-scd
Source: https://github.com/mathisdrn/orca/tree/main/.agents/skills/duckdb-scd
Command: npx skills add https://github.com/mathisdrn/orca --skill duckdb-scd-mathisdrn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tracking historical changes to dimension data in DuckDB requires manual handling of row versioning, expiration dates, and current-record flags, which is error-prone when written from scratch. ## Core Features & Use Cases - SCD Type 2 Table Design: Provides schema conventions with surrogate keys, business keys, validity dates, and is_current flags. - Two-Step MERGE Pattern: Guides the MERGE INTO statement (DuckDB v1.4.0+) to expire changed rows, soft-delete missing records, and insert new ones, followed by an INSERT for new versions. - Use Case: When building a dbt model or DuckDB SQL pipeline that must preserve the full history of entity attributes (e.g., customer locations or names) for audit trails and point-in-time analytics. ## Quick Start Ask the AI to implement an SCD Type 2 dimension table in DuckDB for your entity using the MERGE INTO pattern with begin_date, end_date, and is_current tracking.

Frequently Asked Questions about duckdb-scd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement SCD Type 2 in DuckDB?▼

Use the MERGE INTO statement (available in DuckDB v1.4.0+) to expire changed current rows, soft-delete missing records, and insert new records. Then run a follow-up INSERT to write the new current versions of the rows just expired.

How to track historical changes in a DuckDB dimension table?▼

Design the table with a surrogate key, business key, begin_date, end_date, and is_current flag. Each change creates a new row version while the old version is expired by setting end_date and is_current = false.

Does DuckDB support MERGE INTO for upserts?▼

Yes, DuckDB supports MERGE INTO starting from version v1.4.0. It supports WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, and WHEN NOT MATCHED BY TARGET clauses, enabling full SCD Type 2 logic in a single statement.

Why does SCD Type 2 require two SQL statements in DuckDB?▼

The MERGE statement expires old versions and inserts brand-new records, but it cannot also insert the replacement versions of expired rows in the same pass. A second INSERT joins the source against newly expired rows to write their new current versions.

Can I use this SCD pattern with dbt models?▼

Yes, the pattern works in dbt models targeting DuckDB, since it is plain SQL. Wrap the MERGE and INSERT in a single transaction to keep the dimension consistent if either step fails.