collate-data-diff (also known as data-diff) is a Python library and command-line tool designed to efficiently compare and find differences between rows across two databases or tables. It focuses on performance and scalability for large datasets, providing a fast and accurate way to detect data discrepancies. The current version is 0.11.10, and it maintains an active release cadence with frequent updates.
pip install collate-data-diffVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `data-diff` programmatically to compare two tables in in-memory SQLite databases. It requires `collate-data-diff`, `pandas` (for creating dummy dataframes), and `sqlalchemy` (for database connectivity). Install with `pip install collate-data-diff[sqlite] pandas sqlalchemy`.
Adjust code that processes the output of `diff_tables` to expect single changes as lists of tuples, rather than direct tuples.
Review the official documentation for current limitations and workarounds for SQL Server if it is a critical part of your data stack.
Always provide the `key_columns` argument (e.g., `key_columns='id'`) when initializing `TableSegment` for tables with primary or unique keys.
Install the necessary database extras for your specific database(s) using `pip install "collate-data-diff[<db_name>]"`.
Install the required database driver using pip, e.g., `pip install 'collate-data-diff[presto]'` for PrestoDB. Replace `presto` with the appropriate database driver if you are using a different database like `mysql`, `postgresql`, `snowflake`, etc.
Verify the database connection string, credentials (username, password), host, and port. Ensure the database server is running and accessible from where `collate-data-diff` is being executed. Check firewall rules if applicable.
Explicitly cast or specify the collation for the differing columns in your SQL queries or configuration to ensure they are compared using the same collation. For example, `ON a.ColumnName COLLATE SQL_Latin1_General_CP1_CI_AS = b.ColumnName COLLATE SQL_Latin1_General_CP1_CI_AS`.
Ensure that the columns being compared across both tables have compatible data types. If types differ (e.g., an ID column is `VARCHAR` in one table and `INT` in another), cast one of the columns to match the other's type in your database view or using a `WHERE` clause, or ensure the library's configuration correctly handles type conversions for the specific columns.