Postgresql Plpgsql Loop Through Array Python Memory Allocation