Skip to content

fix(truncate): include materialized views in TRUNCATE#1751

Merged
dimitri merged 1 commit into
mainfrom
fix/truncate-includes-matviews
Jun 28, 2026
Merged

fix(truncate): include materialized views in TRUNCATE#1751
dimitri merged 1 commit into
mainfrom
fix/truncate-includes-matviews

Conversation

@dimitri

@dimitri dimitri commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Problem

When using MATERIALIZE VIEWS view_name AS $$ SELECT ... $$ together with WITH truncate, the pre-COPY TRUNCATE step silently skips every materialized view.

The root cause: fetch-metadata calls fetch-columns with :table-type :view for materialized views, so they land in schema-view-list rather than schema-table-list. truncate-tables built its target list exclusively from (table-list catalog), which only returns schema-table-list entries. The TRUNCATE SQL was therefore never generated for any matview regardless of any subsequent ALTER TABLE NAMES MATCHING ... RENAME TO.

The COPY phase already did the right thing — optimize-table-copy-ordering uses (nconc table-list view-list) — but the TRUNCATE step had not been updated to match.

Fix

Include (view-list catalog-or-table) alongside (table-list catalog-or-table) in the catalog and schema branches of truncate-tables. The table branch is unchanged (a single table object is always concrete).

v4 status

Not affected. Matviews with an explicit SQL definition are handled by materialize-views! which always runs DROP TABLE IF EXISTS + CREATE TABLE before COPY. Matviews without an explicit SQL definition are merged into cat and go through the regular per-entry TRUNCATE loop. Neither path has this miss.

Closes #1591.

When MATERIALIZE VIEWS ... AS $$ ... $$ is used with WITH truncate,
the materialized views are stored in schema-view-list (because
fetch-columns is called with :table-type :view) rather than
schema-table-list. truncate-tables only iterated over table-list,
so the TRUNCATE statement was never generated for any matview — the
summary showed 'Truncate: 0' even when truncate was requested.

The COPY phase already does the right thing: optimize-table-copy-ordering
uses (nconc table-list view-list). Align truncate-tables to match.

Closes #1591.
@dimitri dimitri merged commit b3c3728 into main Jun 28, 2026
37 checks passed
@dimitri dimitri deleted the fix/truncate-includes-matviews branch June 28, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL to Postgres Data Only with Truncate target table not truncating table before loading.

1 participant