Postgresql Loop Through Dataframe