Corin <wakathane@gmail.com> writes:
> Sorry, stupid me - it's not a bug, pg is perfectly right!
> The query was just wrong, because I used the wrong column in the
> SUM(...) function.
Yah. The reason the error message was phrased that way is that the SUM
argument is a variable of the outer query, so the aggregate is also
considered an aggregate of the outer query.
regards, tom lane