I looked at this a little, and I was able to recreate your problem. This might be a RI bug in postgresql, but I'm not 100% sure yet. I did notice that I was able to delete a static page (I had to set live and latest revision to null first), if I recreated the steps individually in the context of a transaction. I'm going to look into this some more when I get the time, but in the mean time, I would suggest trying to convert the sql functions to tcl procs which then wrap the individual steps in a transaction.