--- Raimon Fernandez <coder@montx.com> wrote:
>
> yes, what I want really is the Sum(b.value_d) - sum(b.value_h)
> accumulate
>
> will be faster a function for this that this SELECT ... ?
Using a custom function could be comparable to a pure SQL statement in performance. However,
sometimes function like this can hide details of the query from the PostgreSQL optimizer. If this
happens you will see poor query performance.
>
> GlobalGest=# SELECT A.oid, A.concepte, A.deure, A.haver
--Your are missing a comma here ^
> (sum( B.deure )-sum(B.haver)) AS value_sum
> FROM assentaments AS A
> INNER JOIN assentaments AS B
> ON A.oid <= B.oid
> WHERE A.numero=11189
> GROUP BY A.oid, A.concepte, A.deure, A.haver
> ORDER BY A.oid;
> ERROR: schema "a" does not exist
What version of PostgreSQL are you using?
Your version of the query will need to look like this:
SELECT A1.oid, A1.concepte, A1.deure, A1.haver,
(sum( A2.deure )-sum(A3.haver)) AS value_sum
FROM Assentaments AS A1
INNER JOIN Assentaments AS A2
ON A1.oid <= A2.oid
INNER JOIN Assentaments AS A3
ON A1.oid <= A3.oid
WHERE A1.numero=11189
GROUP BY A1.oid, A1.concepte, A1.deure, A1.haver
ORDER BY A1.oid;
Regards,
Richard Broersma Jr.