New version of upsert for older postgresql versions -doesn't work well