Modifying the 'insert on duplicate update' query for pgsql