Subject merging two records
Author unordained
Scenario:
- you have a table of "contacts"
- you have a wide range of tables with FK's that refer to those contacts, "on
update cascade on delete set null"
- you need to merge two contacts into one

What we've done before is write code to use the system catalog to find all FK's
that refer to a given table, find all rows that refer to a given row being merged
into another (source), manually update all referring rows to point to the one
being merged-into (destination) then delete or otherwise merge the two rows
together.

(Reminder: a table may have only one PK, but it could have several unique keys,
each of which could be a FK target; so this operation, "in general" can be pretty
complex. And there's the worry that one of those FK targets might be unique but
nullable, and the source row has non-null values while the destination one has
nulls, so you can't actually move the references over without filling those in
first...)

FK's support on-update-cascade. PK's can change. The whole first part of this is
essentially what the DB has to do anyway when you modify the PK of a row --
except you can't because the destination PK value already exists, so you have to
do it all by hand. Has anyone found a more elegant solution that uses the tools
already made available? Has there been a proposed atomic operation for this in a
new SQL standard that I've not heard about? I'd be satisfied with "move all
references to row X over to row Y", without worrying about actually merging/
deleting the source row.

-Philip