How to fix Group function is nested too deeply in PostgreSQL | DevErrors