Abdul-wahid Paterson <aw@lintrix.net> writes:
> ... Are there occasions when it is better to
> do the calculations outside of Postgres?
There are, but without details it's impossible to opine whether yours is
one. A "simplified" version of the query is not enough detail. Give us
the exact query, the complete schemas for the tables involved, and the
information reported by EXPLAIN ANALYZE, and then we might be able to
offer useful help.
regards, tom lane