Postgresql Cursor Fetch Loop Example