Skip to content

Fix replacement in attached Postgres catalogs - #6078

Open
clowrance-proppilot wants to merge 1 commit into
SQLMesh:mainfrom
clowrance-proppilot:fix/duckdb-attached-postgres-replace
Open

clowrance-proppilot wants to merge 1 commit into
SQLMesh:mainfrom
clowrance-proppilot:fix/duckdb-attached-postgres-replace

Conversation

@clowrance-proppilot

@clowrance-proppilot clowrance-proppilot commented Sep 21, 2026

Copy link
Copy Markdown

Description

DuckDB does not support CREATE OR REPLACE TABLE for tables in an attached Postgres catalog. SQLMesh currently selects replacement behavior using the current DuckDB catalog rather than the target table catalog, so a full refresh of an attached Postgres table attempts unsupported DDL. It also fails when the physical table has dependent SQLMesh virtual-layer views.

This change:

  • detects catalog type from the target table catalog
  • replaces attached Postgres tables with DROP TABLE IF EXISTS ... CASCADE followed by the normal create path
  • adds a regression test for target-catalog lookup and generated replacement SQL

SQLMesh recreates the virtual-layer views after physical model evaluation, so cascading those dependencies matches the full-refresh lifecycle.

Related context:

This PR addresses physical table replacement in an attached Postgres catalog; it does not claim to close #5438 by itself.

Test Plan

  • make style
  • make fast-test
  • pytest tests/core/engine_adapter/test_duckdb.py -q

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: clowrance-proppilot <clowrance@propertypilot.com>
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.

SQLMesh generates DROP TABLE for PostgreSQL views when using DuckDB engine

1 participant