Postgresql Loop Through Array Python Question