How to fix Invalid cursor state in PostgreSQL | DevErrors