Fix select_or_insert handling