Postgresql Cursor Fetch Loop Example Python