Idly thumbing through the code, I came across something that might possibly explain your results. Do the rows being updated contain NULLs in the foreign-key columns? I see that ri_KeysEqual() treats two null values as not equal, which might be overzealous respect for SQL null semantics in this context. regards, tom lane