Forums

Please or Register to create posts and topics.

Comments on the Gemini Script for Deduplication of Children

DELETE FROM ChildTable
WHERE RecID NOT IN (
SELECT MIN(RecID)
FROM ChildTable
GROUP BY ChildID, FamilyID
);

This doesn't look quite right to me, or perhaps I'm missing what it's trying to accomplish. It appears to me that if a child is in more than one family, it will delete the child from every family but one. But what if a child validly belongs in more than one family? There is no checking to see if the parents are the same in both families.

And even so, it seems to me that the proper approach is to merge duplicate families. For example, suppose person #1 and person #2 are the parents in family #1 and also in family #2. RM will prevent this from happening from the RM user interface, but it's a common problem after imports of various kinds. Then suppose person #3 is a child in family #1 and person #4 is a child in family #2. The proper merge is probably to move child #4 to family #1, move all foreign key references that are to family #2 to family #1 (e.g., citations, media, facts, etc. for family #2 should move to family #1), and delete family #2. I apologize if I'm missing the point.

Well, Jerry, the page itself missed the mark in that I assumed that the problem case described was simply that there were two (or more) records in the ChildTable for the same ChildID-FamilyID pair. Turns out that assumption was wrong. Once I got a database with the manifested problem of doubled Spouses and Parents counts, it turns out that there are two records in the FamilyTable for the same FatherID-MotherID pair and two records for the same child in the ChildTable, one for each of the duplicate parents' FamilyID. So that query did nothing to fix the problem.

Nor does it affect any of the ChildTable records that do or don't link a child to duplicate couples because they are all unique pairs of ChildID-FamilyID. Therefore the set of MIN(ChildID) grouped by ChildID, FamilyID is the same as the full set of ChildID's. There are no ChildID's NOT IN the set of MIN(ChildID)'s to be deleted.

You are right in your description of the "proper approach" but we did not need the full solution in this case because there is nothing like citations, media, facts, etc. that can be tied to a ChildTable record. However, the actual case does bring in the complication that there are family-type events (Marriage, e.g.) for the duplicate couples and, oddly, the occasional child linked to only one of the duplicate couples. So I'm having to take into account this more complex situation but, fortunately, there are no citations, media, tasks, webtags in the download.

Unfortunately, the example case on FSFT has been changed by someone breaking the maternal line that converged with the paternal line a couple of generations higher. I was going to test the free Ancestral Quest 16 Basic on it to see if it suffered the same duplications as RM. If it did, then there's something they have in common. If not and it replicates what we see on FSFT, then RM is truly at fault.

Tom

This got me checking my own database, and I noticed 3 duplicated FamilyTable records.

In the RM UI, one sees that the husband and wife both connected with the same person twice.
I and Copilot, came up with a nice Python script to detect and merge duplicate family records, move the children and all attached items (citations, media, etc)

It gave a good result in my database. My own initial, manual try didn't do as well.
Use it on a copy of your database until you're sure. I haven't "released" it yet, so you'll have to download the files manually.

https://github.com/RichardOtter/Genealogy-scripts/tree/main/Merge%20duplicate%20family%20records