The view queries another view that does a lot of UNION ALLs of tables. This particular case I'm dealing with about 60 tables unioned together.
The resulting error is:
ERROR: out of memory DETAIL: Failed on request of size ???
The issue seems a straight match with this link I found online: http://stackoverflow.com/questions/11878035/postgresql-9-1-out-of-memory-during-create-table-as-select
After doing a lot of googling, I've tried setting FETCH_COUNT on psql AND/OR setting work_mem. I'm just not able to work around this issue, unless if I take most of the MAX() functions out but just one.
Would anyone give me some hints on how to resolve this issue?