Job

Merge duplicate records in one table and add the constraint that stops new ones

Duplicate rows in one PostgreSQL or MySQL table are merged on a copy, with removed rows archived, a reverse script that is run, a reconciliation report and a non-blocking uniqueness guard.

What you get

  • A duplicate-group report with counts and a masked sample, and the group counts compared between production and the masked copy
  • A merge script that runs in small transactions and can be re-run, the archive of removed rows and the log of every reference moved
  • A reverse script, and the log of running it on the copy with table checksums before the merge and after the reverse

and 2 more

Price
From $905Final price agreed before we start
You pay
From $905, agreed in writing before work starts and paid after the agreed checks pass and you sign off.
Term
One job
How soon
We set up the day after you ask and start work within three days.

No passwords, keys, card details or admin invites needed to start.

Price and terms in full

From $905 Final price agreed before we start

From $905 for one table of up to 2 million rows with up to ten dependent tables and one match rule. More tables, several match rules or a table without declared references is quoted after we have seen the schema.

You pay
From $905, agreed in writing before work starts and paid after the agreed checks pass and you sign off. No payment before sign-off.
Includes
One table merged on a restored copy against a written survivor rule; Merge script, archive of removed rows, log of references moved, reverse script run on the copy, reconciliation report; The uniqueness guard migration in its non-blocking form and the production order of steps
Term
One job
Technology
PostgreSQL, MySQL, SQL, Data-quality, Constraints
Delivery
Start window and delivery date agreed in writing after eligibility and access checks.

Nothing is charged or booked when you send your details. The written quote confirms the total price and any tax before you accept.

What usually happened

You might be seeing

  • The same real-world thing appears in several rows, each with different related records
  • Adding a unique constraint fails because existing rows collide
  • Deleting an extra row would orphan or cascade away orders, invoices or history

Who it’s for: An engineering manager or founder whose database holds several rows for the same customer, product or account, and who dares not delete the extras.

The result: On a restored copy, every duplicate group is merged into one surviving row, every reference in the agreed tables points at it, each removed row is archived in full, a reconciliation report accounts for every row, and a reverse script is run to show the starting state comes back. A unique index, built without blocking writes, prevents the same duplicates from returning. You receive the scripts to run in production.

When it starts, and why it happens

Usually starts when: Reports double-count, a unique index cannot be added because duplicates exist, or support finds the same person under two accounts with orders attached to each.

Rows that describe the same real-world thing exist several times in a table, because nothing enforced uniqueness, a null counted as distinct, an import or a retry inserted twice, or two systems each created a record. Other tables point at each copy, so removing the extras either fails, orphans data or cascades it away. A safe merge needs an agreed rule for which row survives, every reference repointed first, a report that shows nothing was lost and a way back that restores the removed rows themselves, not only a list of their ids.

What you get

All 5 things you get
  • A duplicate-group report with counts and a masked sample, and the group counts compared between production and the masked copy
  • A merge script that runs in small transactions and can be re-run, the archive of removed rows and the log of every reference moved
  • A reverse script, and the log of running it on the copy with table checksums before the merge and after the reverse
  • A reconciliation report: rows before and after, references repointed per table, rows removed and archived, and a check that nothing is orphaned
  • The migration that adds the uniqueness guard in its non-blocking form, and a runbook for your production window with the order of steps and what to do if the guard build fails

Included

  • One table of one entity in one PostgreSQL, or MySQL with InnoDB, database, and the tables that reference it
  • Agree an exact or deterministic matching rule, such as a normalised email or a reference number, and a survivor rule. Rows where the match key is empty or null never match each other, and the survivor keeps its own values: nothing is copied into it from the removed rows
Show 3 more
  • Find the duplicate groups, archive each removed row in full, log every reference moved (table, primary key, old key, new key) and repoint references in the dependent tables on a restored copy
  • Write and run a reverse script on the copy that restores the archived rows and the old references from the log
  • Produce a reconciliation report and add a unique index that stops recurrence, built in the engine's non-blocking form; a rule that covers only some rows is a partial unique index on PostgreSQL and, because MySQL has no partial indexes, a unique index on a generated column that is NULL outside the rule

Not included

  • Running the merge against production; you do that after a restore point you have tested
  • Fuzzy or judgement-based matching of names or addresses
  • Deduplicating across systems such as a CRM or accounting package
  • More than one entity table, or more than 20 dependent tables
Show 3 more
  • Combining field values from the duplicates into the survivor
  • Undoing edits made after the merge: the reverse script restores what the merge changed, and reports any row changed since instead of overwriting it
  • Records you must keep unchanged; you name them and they are excluded from the rule, and they must not share a match key with another row

How we know it’s done

Agreed with you before work starts. Each check produces evidence you keep.

Merge duplicate records: 5 checks and the evidence you keep5 checks, each with the evidence you keep: 1 No key value in more than one row (evidence: Duplicate count query before and after); 2 Every reference points at surviving row, zero orphans (evidence: Orphan check per dependent table); 3 Report accounts for every row: surviving, removed, excluded (evidence: Reconciliation report, archive and log counts); 4 Reverse script returns tables to checksums before merge (evidence: Checksums before merge and after reverse); 5 Unique index rejects repeated key, table never blocked (evidence: Build log, insert rejection, recovered build). When all pass: sign-off (Review sample, report, confirm survivor rule, sign off). When a check fails: You do not pay for this fixed scope.What we checkEvidence you keep1 No key value in more than one rowDuplicate count query before and after2 Every reference points at surviving row, zeroorphansOrphan check per dependent table3 Report accounts for every row: surviving,removed, excludedReconciliation report, archive and log counts4 Reverse script returns tables to checksumsbefore mergeChecksums before merge and after reverse5 Unique index rejects repeated key, table neverblockedBuild log, insert rejection, recovered buildAll pass: sign-offReview sample, report, confirm survivor rule, sign offA check failsYou do not pay for this fixed scopeYou decide here Merge duplicate records: 5 checks and the evidence you keep5 checks, each with the evidence you keep: 1 No key value in more than one row (evidence: Duplicate count query before and after); 2 Every reference points at surviving row, zero orphans (evidence: Orphan check per dependent table); 3 Report accounts for every row: surviving, removed, excluded (evidence: Reconciliation report, archive and log counts); 4 Reverse script returns tables to checksums before merge (evidence: Checksums before merge and after reverse); 5 Unique index rejects repeated key, table never blocked (evidence: Build log, insert rejection, recovered build). When all pass: sign-off (Review sample, report, confirm survivor rule, sign off). When a check fails: You do not pay for this fixed scope.1 No key value in more than one rowEvidence: Duplicate count query before andafter2 Every reference points at survivingrow, zero orphansEvidence: Orphan check per dependent table3 Report accounts for every row:surviving, removed, excludedEvidence: Reconciliation report, archive andlog counts4 Reverse script returns tables tochecksums before mergeEvidence: Checksums before merge and afterreverse5 Unique index rejects repeated key,table never blockedEvidence: Build log, insert rejection,recovered buildAll pass: sign-offReview sample,report, confirmsurvivor rule, signoffA check failsYou do not pay forthis fixed scopeYou decide here
The checks we run, the evidence you keep for each, and what happens next. Drawn from the checks on this page.
The 5 checks in full, with the evidence you keep
  1. On the restored copy, no value of the agreed match key appears in more than one row after the merge; the records you excluded sit outside the duplicate groups and are unchanged.

    Evidence: The duplicate count query before and after.

  2. Every reference in the agreed dependent tables points at an existing surviving row, with zero orphans.

    Evidence: An orphan check per dependent table.

  3. The reconciliation report accounts for every row: surviving, removed and excluded. The archive holds one full row for each removed row, the reference log has one line for each reference moved, and the count of related rows per table is the same before and after.

    Evidence: The reconciliation report with the archive and log counts.

  4. After the merge, the reverse script run on the same copy (rows added by the guard-rehearsal insert script removed first, then the guard removed) returns the entity table and every dependent table to checksums equal to those taken before the merge.

    Evidence: The checksums before the merge and after the reverse, per table, and the reverse run log.

  5. The guard, built in the non-blocking form while a script keeps inserting rows on the copy, ends as a valid unique index that rejects an insert repeating the match key. A duplicate inserted deliberately during the build is either rejected or makes the build fail, the table is never blocked, and the runbook's recovery step then ends with a valid index.

    Evidence: The build log with the insert script running, the rejection from a test insert, and the log of the failed and recovered build.

Sign-off. You review the masked sample, the reconciliation report and the reverse run, confirm the survivor rule was applied, and sign off in writing. Payment follows sign-off; running the script in production stays your decision.

If it fails. If the reconciliation shows rows or references unaccounted for on the copy, or the reverse script does not return the checksums to the state before the merge, you do not pay for this fixed scope and keep the findings. If the duplicates need human judgement, we say so and stop.

How we deliver

We arrange the work and independent review, then show you the result against the agreed checks. You keep authority over your systems.

Merge duplicate records: how it is delivered, step by stepSteps in order: 1 Agree in writing (match rule, survivor rule, dependent tables, restored copy); 2 Compare group counts (masked copy, stop if they differ, review sample); 3 Take checksums (then write merge as small re-runnable transactions); 4 Run on copy (reconcile row counts and references table by table); 5 Add uniqueness guard (non-blocking form while a script keeps inserting rows); 6 Write reverse script (run reverse on copy, compare checksums before merge); 7 Independent review (scripts and report, then hand over the runbook); 8 sign-off (Review sample, report, confirm survivor rule, sign off). You decide at step 1, step 2 and the sign-off. We stop and tell you if any of the 5 conditions listed on this page applies.1 Agree in writingmatch rule, survivorrule, dependent tables,restored copy2 Compare groupcountsmasked copy, stop ifthey differ, reviewsample3 Take checksumsthen write merge assmall re-runnabletransactions4 Run on copyreconcile row countsand references table bytable5 Add uniquenessguardnon-blocking form whilea script keeps insertingrows6 Write reversescriptrun reverse on copy,compare checksumsbefore merge7 Independentreviewscripts and report, thenhand over the runbook8 Sign-offReview sample, report,confirm survivor rule,sign offWe stop and tell you ifany of the 5 conditions listed on this page appliesYou decide here Merge duplicate records: how it is delivered, step by stepSteps in order: 1 Agree in writing (match rule, survivor rule, dependent tables, restored copy); 2 Compare group counts (masked copy, stop if they differ, review sample); 3 Take checksums (then write merge as small re-runnable transactions); 4 Run on copy (reconcile row counts and references table by table); 5 Add uniqueness guard (non-blocking form while a script keeps inserting rows); 6 Write reverse script (run reverse on copy, compare checksums before merge); 7 Independent review (scripts and report, then hand over the runbook); 8 sign-off (Review sample, report, confirm survivor rule, sign off). You decide at step 1, step 2 and the sign-off. We stop and tell you if any of the 5 conditions listed on this page applies.1 Agree in writingmatch rule, survivor rule, dependent tables,restored copy2 Compare group countsmasked copy, stop if they differ, reviewsample3 Take checksumsthen write merge as small re-runnabletransactions4 Run on copyreconcile row counts and references table bytable5 Add uniqueness guardnon-blocking form while a script keepsinserting rows6 Write reverse scriptrun reverse on copy, compare checksumsbefore merge7 Independent reviewscripts and report, then hand over therunbook8 Sign-offReview sample, report, confirm survivor rule,sign offWe stop and tell you ifany of the 5 conditions listed on this pageappliesYou decide here
How we deliver it, in order. A box with a coloured border is where you decide. Drawn from the delivery steps on this page.
The 7 delivery steps in full
  • Agree the match rule, the survivor rule, the dependent tables, the records to leave alone and the restored copy in writing
  • Compare the duplicate-group count on production (run read-only by your engineer) with the count on the masked copy; stop if they differ. Then find the groups and review a masked sample with you before anything is merged
  • Take a checksum of the table and of each dependent table, then write the merge as small, re-runnable transactions: archive each removed row in full, log each reference moved, repoint references, then remove the extras
  • Run it on the restored copy and reconcile row counts and references table by table
  • On the merged copy, add the uniqueness guard in the non-blocking form while a script keeps inserting rows, show that inserting a duplicate is rejected, and rehearse the recovery step for a build that fails
  • Remove the rows the insert script added during the guard rehearsal, write the reverse script, drop the guard built in the previous step, run the reverse on the copy and compare the checksums with those taken before the merge
  • Independent review of the scripts and report, then hand over the runbook for your production window

This is a one-off job, not emergency cover or a subscription. We confirm eligibility, the total price, a start window and a delivery date before you accept. Work starts only after agreed inputs, secure access and any permissions are in place. Hosting and database charges are excluded unless the written quote includes them. No charge or booking is created by sending a message.

When it fits, and when we stop

It fits when

  • PostgreSQL, or MySQL with InnoDB, on a version you can name, with the table, its references and a restore point you have tested. We check the guard build against that version's manual at intake; this page was checked against PostgreSQL 18 and MySQL 8.4
  • The match key can be expressed as exact values or a deterministic normalisation
Show 2 more
  • A restored copy can be prepared with personal data replaced consistently, so equal values stay equal under the match rule, and your engineer can run one read-only count of duplicate groups on production and on the copy and send both figures; they must be equal
  • Someone with authority over the data agrees the survivor rule in writing

We stop and tell you if

  • Most duplicate groups need a person to judge whether they are the same thing
  • No restore point has ever been restored successfully
  • References to the table are not declared and cannot be listed by you or found by us
Show 2 more
  • Some records must be kept as they are for a reason you cannot lift, and they sit inside duplicate groups
  • The group counts on production and on the masked copy differ, so the copy does not behave like the data

Check whether this job fits

These questions check that a deterministic rule can decide what is a duplicate. No data is needed.

Answer 4 questions to see if it fits
Can you state exactly what makes two rows the same thing?
Do other tables point at this one, and are those links declared?
Do you have a backup you have restored and checked?
Which engine holds the table?

Answer the questions to see whether this job fits.

Nothing is sent anywhere until you choose to email us.

Ask about this job

Checks you can run yourself
  1. Count the groups without changing anything

    On a copy, ask your engineer to count how many values of your match key appear more than once, leaving out rows where the key is empty. This only reads.

    SELECT count(*) FROM (SELECT lower(email) FROM customers WHERE email IS NOT NULL AND email <> '' GROUP BY lower(email) HAVING count(*) > 1) AS d;

    Look for: The number of duplicate groups. Send the count and the table size, not the values. Later, the same count on the masked copy must equal the count on production.

What could go wrong

5 risks, and how we handle each

There are two ways back. The reverse script restores every archived row under its original key and sets each moved reference back from the log, after first removing the guard. We run it on the copy as part of approval and compare table checksums with the state before the merge. In production it undoes the merge only: rows changed since the merge are reported and left alone, and rows added since are untouched. Your tested restore point restores the whole database but also loses every write made since it was taken. The guard has a script that removes it.

Scroll the table sideways to read it all.

RiskHow we handle it
Two rows that look the same are different things and are merged.The rule is exact or deterministic, you approve a masked sample first, and the archive and reference log let any group be put back.
A foreign key with a cascading delete removes related history.References are repointed before any delete, and the reconciliation report counts related rows before and after.
The masked copy shows different duplicate groups from production, so the rehearsal proves nothing.The group counts on production and on the copy are compared before any work; if they differ we stop.
Production data changed between the copy and the run, or a new duplicate arrives while the guard is being built.The runbook fences the writers that create this entity, re-runs the duplicate count immediately before the merge and stops if the groups differ from those reviewed. The guard is built last in the non-blocking form; a build that fails because of a new duplicate fails safely and the runbook says how to recover.
Building the uniqueness guard on a large live table blocks writes.The build uses PostgreSQL's CREATE UNIQUE INDEX CONCURRENTLY, or MySQL's online ALTER TABLE with ALGORITHM=INPLACE and LOCK=NONE, which stops with an error instead of locking if the server cannot honour it. The build is rehearsed on the copy under inserts.

A second reviewer checks that the survivor rule is applied as written, that no reference is left pointing at a removed row, that the script cannot cascade-delete related data, and that the reverse script was run and not only written. Your authorised person approves the sample and runs the script.

Need to keep it working?

A full-time AI agent can look after this kind of work, or tell us what you want looked after when you ask.

What ongoing work would cover, and what it does not

Discuss a monthly database health review so new duplicates, orphans and growth are found early.

Ongoing work is separately scoped and quoted: no monitoring, response-time guarantee or automatic subscription is included in this job.

What you can check

Other ways to get this done
  • PostgreSQL documents that unique constraints treat nulls as distinct by default, with NULLS NOT DISTINCT to change that, and unique partial indexes for rules covering some rows. www.postgresql.org
  • PostgreSQL's INSERT ... ON CONFLICT gives an atomic insert-or-skip under concurrency, which prevents new duplicates once a unique index exists. www.postgresql.org
  • MySQL's CREATE INDEX manual says a UNIQUE index permits multiple NULL values, and its manual on secondary indexes says an InnoDB unique index can be defined on a virtual generated column. dev.mysql.com

Questions

Can you decide which duplicates are the same person?

Only by a rule you agree. Where a judgement is needed per case, this fixed job does not fit and we say so.

What stops duplicates coming back?

A unique index on the match key, built without blocking writes and tested with an insert that must be rejected. A rule that covers only some rows is a partial unique index on PostgreSQL; MySQL has no partial indexes, so there it is a unique index on a generated column that is NULL outside the rule.

Can the merge be undone?

Yes, on the copy and in the runbook. Each removed row is archived in full, every reference we move is logged, and a reverse script puts both back; we run it and show the table checksums match the state before the merge. It undoes the merge, not edits made afterwards. Your tested restore point reverts everything, including later writes.

Do you touch our production database?

No. We work on a restored copy and hand you a script and a runbook. You run it after your own restore point.

Ask about this job

What to send us, what comes later, and who owns what

Send us

  • The engine and version, the table, its approximate row count and what makes two rows the same thing
  • How many rows you believe are duplicated, and the tables that point at it, if you know them
  • Which row you would keep in a duplicate group: the oldest, the newest, the most complete
  • Whether the rule should cover every row or only some, such as only active records
  • Do not send credentials, a dump or real rows in your first message

Later, once you agree

  • A restored copy of the database with personal data replaced consistently, and the duplicate-group count from production and from the copy
  • The schema, including the declared foreign keys, through an authorised company-controlled route
  • The written survivor rule and the list of records that must not change
  • The date of your tested restore and the person who will run the script

You own the database, the code and every credential. We work on a copy you prepare, such as a staging database restored from a backup with personal data removed or replaced, and we hand work back as a pull request or a script. We never ask for production passwords, and we do not connect to your production database. You apply any change to production yourself, after a restore point that you have tested.

Add detail (optional)

A web address anyone can open, with no login in it. No code or logs.

We reply by email. Sending this emails your request to our team; nothing is kept in a website database. Please do not send passwords, keys or customer records. Privacy notice.

Email fallback: open your mail app

If website submission is unavailable, review and send the fallback email yourself. An email fallback is not a website receipt. Or write to hello@syntheticindustry.ai and say which job you mean.

Last revised 13 October 2026