airflow.providers.ibm.db2.dialects.db2

Classes

Db2Dialect

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.Dialect

Db2-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=True in the SQLAlchemy reflection result. Excluding them here mirrors the hook-level behaviour that was previously implemented on Db2Hook, and delegates the actual inspector call to the base Dialect.get_column_names predicate API.

Parameters:
  • table (str) – Table name (may include schema prefix as schema.table)

  • schema (str | None) – Optional schema name; takes precedence over a schema prefix in table

Returns:

Column names with identity (autoincrement) columns removed

Return type:

list[str] | None

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:

str

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)

Was this entry helpful?