Help › Explore a database
Compare the data of two tables
Match the rows of two tables, or a table and a query's result, by key, see what differs side by side, and get the SQL that makes one side like the other.
Querlyn 0.1.0 is not released yet. This help describes it ahead of release.
Data compare reads the rows of two tables, matches them by a key, and lists what differs: rows only one side has, and rows whose values differ, side by side. The tables can be on the same connection or on two connections, in two databases, even on two kinds of database. It never changes anything by itself; it can write the statements that would make one side like the other, for you to review and run.
To compare the structure of two schemas instead, see Compare two schemas. To compare two results already loaded in your tabs, such as a query before and after a change, see Compare two results.
Choose the two sides
| To | Do this |
|---|---|
| Compare a table with another | Right-click a table or view in the sidebar and choose Compare Data With… (). |
| Compare the table of a table tab | Compare Data… in the bar of the table tab. |
| Compare a query's result with a table | With the result shown, choose , or Compare Data With… in the grid's right-click menu. The query runs again, ordered by the key. |
| Start from nothing | with nothing selected asks for both sides, one after the other. |
The side you start from is the left side. A dialog asks for the right side and suggests the same table elsewhere: one the sidebar lists on another connection, else in another database of the same connection, else the same name on another connection of the same kind of database. Choose:
- the Connection (one that is not connected connects to list what it has);
- the Database, where the server has several;
- Table or View, then type its name (
schema.table, or just the table in the connection's default schema) or pick it from the list of tables the sidebar has listed; or Query, then write one statement that only reads.
Choose Compare or press ↩ on macOS or Enter on Windows and Linux; ⎋ on macOS or Esc on Windows and Linux closes the dialog. The new tab reads both sides' columns and keys and starts comparing at once.
In the tab, Change… beside each side chooses another table or query for it (, ), and Swap exchanges them ().
How rows are matched
Rows are matched by a key, shown under the options:
- the left table's primary key, if the right side has its columns;
- else the right table's primary key;
- else a unique key whose columns cannot be NULL, of either side.
The Key button above the rows changes it: tick the columns that identify a row, or choose The key Querlyn finds to go back. A key that is not a primary or unique key on a side may match rows ambiguously; a line says so. Rows whose key repeats on a side are not matched: they are counted and listed as Key repeats. Rows with a NULL in the key match nothing and are counted apart.
Columns are matched by name (exactly, else ignoring case). A column only one side has is not compared, and a line names it. Columns whose types differ are compared by what they hold, and a line names them:
- numbers by value, exactly:
9.50and9.5are the same, and aDOUBLE0.1 is aNUMERIC0.1; decimals are never rounded; - timestamps with a time zone as the same moment;
- JSON by its structure, so spacing and the order of keys do not matter;
- a UUID and text that spells it as the same value;
- NULL equals only NULL: NULL and an empty string differ.
Read the differences
The line above the rows counts everything: how many rows each side had, how many differ, and how many are Identical. Identical rows are counted, not listed. The buttons filter the list:
| Filter | Lists |
|---|---|
| All | Every difference |
| Different | Rows both sides have, with values that differ |
| Only Left | Rows only the left side has (and repeated keys of the left) |
| Only Right | Rows only the right side has (and repeated keys of the right) |
Each row shows its status, the key, then each compared column twice: the left value, then the right. A value that differs from the other side's is highlighted. A side without the row shows a dash.
Move with ↑ on macOS or Up on Windows and Linux and ↓ on macOS or Down on Windows and Linux, ⇞ on macOS or PageUp on Windows and Linux, ⇟ on macOS or PageDown on Windows and Linux, ↖ on macOS or Home on Windows and Linux and ↘ on macOS or End on Windows and Linux. Next and Previous go to the next value that differs, then to the next row (F7, ⇧F7 on macOS or Shift+F7 on Windows and Linux).
Compare Again (⌘R on macOS or Ctrl+R on Windows and Linux) reads both sides again. Stop () cancels both statements on their servers; what was compared until then stays.
Compare large tables
Neither table is loaded whole. Each server sends its rows ordered by the key, and Querlyn walks both in step, holding only the rows not yet matched (a batch or two of each side), so tables of millions of rows can be compared. The first 10,000 differences are kept for the list and the script; every row is counted, and a line says when some were not kept. A script is written only when every difference was kept and no row limit stopped the comparison: narrow a big comparison with WHERE first.
To compare part of a table:
- WHERE takes a condition, as a table tab's WHERE field does
(
region = 'EU'); both sides are read with it. Press ↩ on macOS or Enter on Windows and Linux in it to compare again. - Stop after stops once a side has read 10,000, 100,000 or 1,000,000 rows. Every key up to the last one read is compared; a line names it.
How the order is kept the same
Both servers must send their rows in the same order. Text keys are
therefore sorted by their characters' codes (a binary order) on both,
whatever their collations, so B comes before a, and keys that differ
only in case or accents are different keys. A key that is a number on one
side and text on the other is sorted as text on both. If a server still
sends its rows in another order, the comparison stops and says which keys
came out of order, rather than report rows as missing.
Compare tables on Production
Comparing only reads: each side runs on a session of its own, read-only where the database allows, with the connection's time limits (see Lock waits and timeouts). Every statement is listed in the statement console under Compare.
When a side is on a Production connection, Querlyn says first that it reads the whole table (or every row the WHERE condition selects), and asks once for those two sides. Cancel reads nothing.
Make one side like the other
| Button | Writes |
|---|---|
| Make Right Like Left () | The statements that change the right table to hold what the left has |
| Make Left Like Right () | The same, the other way |
The script opens in a new query tab on the table's connection and
database. Nothing runs: read it, then run it yourself, and the usual
confirmations apply then, on Production too. The script
deletes the rows only the target has, updates the values that differ, and
inserts the rows only the source has, in that order, in the target's
dialect, with values written exactly (decimals as their digits, text
quoted the target's way, NULL as NULL). It starts with comments that say
what it does and what it leaves out.
There is no script, and a line says why, when:
- the target is a query's result, not a table;
- the key is not the target's primary key or a unique key whose columns cannot be NULL (a statement could change several rows);
- a key repeated on either side;
- the comparison did not finish;
- more differences were found than were kept, or the comparison stopped
at a row limit: a script would make the tables only partly alike.
Narrow the comparison with WHERE (
region = 'EU', a range of keys) until every difference is kept, then compare again.
A column the database computes is never written; identity columns get their own values the way each database allows it.
Masked columns
Values of masked columns stay masked in the list, on either side when one side masks the column. They are still compared, so the counts stay right. While screen-share mode is on, a script that would write a masked column's values is refused.
Help for Querlyn 0.1.0. All help topics