How to fix Statement too complex in PostgreSQL | DevErrors