Skip to content
DuckDB community extension

duck_diff

Diff two relations (tables, queries) off a primary key, reporting per-key status (identical/different/left_only/right_only), a JSON summary of changed columns, and per-column left/right values.

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL duck_diff FROM community;
LOAD duck_diff FROM community;

Try it in a temporary SQL session with duck_diff already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Create two sample snapshots

SQL
-- Create two sample snapshots
CREATE TABLE users_v1 AS SELECT * FROM (VALUES
    (1, 'Ada',   '[email protected]',   100),
    (2, 'Linus', '[email protected]',  50),
    (3, 'Grace', '[email protected]',  75)
) t(id, name, email, credits);

CREATE TABLE users_v2 AS SELECT * FROM (VALUES
    (1, 'Ada',   '[email protected]',   120),   -- credits changed
    (2, 'Linus', '[email protected]',  50),   -- unchanged
    (4, 'Mike',  '[email protected]',   10)    -- new (id 3 removed)
) t(id, name, email, credits);

-- Diff them off the primary key
SELECT id, diff_status, diff_data, credits_left, credits_right
FROM table_diff('FROM users_v1', 'FROM users_v2', pk := 'id')
ORDER BY id;

-- Or get counts and percentages per status
SELECT * FROM table_diff_summary('FROM users_v1', 'FROM users_v2', pk := 'id');

Provided by avaitla. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

duck_diff finds the difference between two tables — which can be on entirely different systems if needed. Typical uses:

Each key gets a status (identical / different / left_only / right_only), a JSON diff_data of the changed columns, and <c>_left / <c>_right / <c>_diff_status columns. Composite keys are supported; upcast_types, numeric_tolerance, timestamp_precision, null_equals_empty, and columns / ignore / context control the comparison across engines.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
avaitla/duck_diff
License
MIT
Maintainers
avaitla
Written in
C++
Build source
00f636e5a62e
Build definition
Community descriptor