Skip to content

Commit cd67d73

Browse files
committed
fix(db2): override _truncate_table to append IMMEDIATE keyword
Db2 requires TRUNCATE TABLE <name> IMMEDIATE. The base class omits the mandatory IMMEDIATE keyword, causing SQL0104N: 'unexpected token END-OF-STATEMENT, expected IMMEDIATE' Pattern follows trino.py which also overrides _truncate_table with a dialect-specific suffix for the same reason.
1 parent 8de1f45 commit cd67d73

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • sqlmesh/core/engine_adapter

sqlmesh/core/engine_adapter/db2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,13 @@ def _create_table_like(
732732
)
733733
)
734734

735+
def _truncate_table(self, table_name: TableName) -> None:
736+
# Db2 requires the IMMEDIATE keyword after the table name; without it
737+
# the statement fails with SQL0104N (unexpected token END-OF-STATEMENT,
738+
# expected IMMEDIATE).
739+
table = exp.to_table(table_name)
740+
self.execute(f"TRUNCATE TABLE {table.sql(dialect=self.dialect, identify=True)} IMMEDIATE")
741+
735742
def _convert_df_datetime(self, df: DF, columns_to_types: t.Dict[str, exp.DataType]) -> None:
736743
"""
737744
Db2 has strict type casting rules: TIME columns cannot be cast to TIMESTAMP or

0 commit comments

Comments
 (0)