Postgresql Loop Through Dictionary