airflow.providers.ibm.db2.dialects.db2¶
Classes¶
Db2-specific SQL dialect implementation. |
Module Contents¶
- class airflow.providers.ibm.db2.dialects.db2.Db2Dialect(hook, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.dialects.dialect.DialectDb2-specific SQL dialect implementation.
Provides Db2-specific SQL generation, particularly for MERGE (upsert) operations.
- get_column_names(table, schema=None, predicate=None, **kwargs)[source]¶
Return column names for a table, excluding identity columns.
Db2 marks auto-generated identity columns with
autoincrement=Truein the SQLAlchemy reflection result. Excluding them here mirrors the hook-level behaviour that was previously implemented onDb2Hook, and delegates the actual inspector call to the baseDialect.get_column_namespredicate API.
- generate_replace_sql(table, values, target_fields, **kwargs)[source]¶
Generate MERGE SQL statement for Db2.
Db2 doesn’t support REPLACE INTO syntax. Instead, it uses MERGE statements for upsert operations.
- Parameters:
table – Name of the target table
values – The row to insert/update
target_fields – The names of the columns to fill in the table
kwargs – Additional parameters, including replace_index: list of column names to use for matching (defaults to primary keys)
- Returns:
The generated MERGE SQL statement
- Return type:
Example generated SQL:
MERGE INTO table AS t USING (VALUES (?, ?, ?)) AS s(col1, col2, col3) ON t.pk = s.pk WHEN MATCHED THEN UPDATE SET t.col1 = s.col1, t.col2 = s.col2 WHEN NOT MATCHED THEN INSERT (col1, col2, col3) VALUES (s.col1, s.col2, s.col3)