# duckdb/append.sql

append.sql — insert-only load; only inserts genuinely new rows (DuckDB)

append.sql — insert-only load; only inserts genuinely new rows (DuckDB)

## Context fields

- `.HistorySchema`
- `.HistoryTable`

## Template

```sql
{{- /* append.sql — insert-only load; only inserts genuinely new rows (DuckDB) */ -}}
{{- /* Also used for dedup_append — semantic distinction is at the agent context level */ -}}
{{- /* Reads compare_source: under full the _transform view (FULL OUTER JOIN), under    */ -}}
{{- /* delta and window the SDK's scoped compare (ADR-161), which computes the action.  */ -}}
{{- /* Only action=1 (INSERT) rows are appended — duplicates and unchanged rows skipped. */ -}}
{{- /* Tier B: no ON CONFLICT — DuckDB unique indexes treat NULLs as distinct, so the     */ -}}
{{- /* (hpk, valid_to) index cannot dedup active rows; the action filter does it instead. */ -}}
{{ template "duplicate_key_guard" . -}}
INSERT INTO "{{ .HistorySchema }}"."{{ .HistoryTable }}" (
    {{ template "business_col_list" . }}, {{ template "amf_system_cols" . }}
)
SELECT {{ template "business_col_list" . }}, {{ template "amf_system_vals" . }}
FROM   {{ template "compare_source" . }} stg
WHERE  stg.amf_cdc_action = 1
```

## Provenance

| | |
| --- | --- |
| Platform | `duckdb` |
| File | `duckdb/append.sql` |
| Version | `v1.3.1` |
| Lines | 14 |
| SHA-256 | `738e58f21e26721fa1885a394514361dadc2ef35c2466ada33c79acfb4a2539d` |
