compare_tables
- sqlcompyre.compare_tables(engine: Engine, left: Select | FromClause | str, right: Select | FromClause | str, join_columns: list[str] | None = None, ignore_columns: list[str] | None = None, column_name_mapping: dict[str, str] | None = None, float_precision: float = 2.220446049250313e-16, collation: str | None = None, ignore_casing: bool = False, infer_primary_keys: bool = False) TableComparison[source]
Compare two tables in the database.
- Args:
engine: The engine to use to access the database. left: The “left” database table for the comparison. The table can optionally be
specified with schema (and database) name. For MSSQL, the table name can be specified as
[[<database>.]<schema>.]<table>depending on the “default” database of the provided engine and the database’s default schema. If provided as a SQLAlchemy table, the name is extracted automatically.- right: The “right” database table to compare to the “left” table. The naming convention
follows the convention for the “left” table.
- join_columns: The columns to join the tables on in order to compare column values. If
not provided, defaults to the union of primary keys. The corresponding primary key(s) of the right table are determined via
column_name_mapping.- ignore_columns: Columns to ignore to evaluate equality. These column names should
reference the left table: corresponding columns in the right table are determined via
column_name_mapping. Primary key columns passed here are ignored.- column_name_mapping: A mapping from column names in the left table to column names in
the right table. If not provided, defaults to mapping columns with the same names.
- float_precision: The precision of floating point comparisons. Values with an absolute
difference below the precision are considered equal.
- collation: An optional collation that is used to compare strings. Useful for making
case-sensitive comparisons even if a table’s column uses a case-insensitive collation.
- ignore_casing: Whether casing (e.g. capitalization) should be ignored when matching
column names. This is valuable if only interacting with the database through case-insensitive tools (e.g. SQL).
- infer_primary_keys: Allows SQLCompyre to build a primary key from all matching columns
automatically and use it to match tables even if they do not have a primary key.
- Returns:
A table comparison object that can be used to explore the differences in the tables.