From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | Raimon Fernandez <coder(at)montx(dot)com>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: aggregate function ? |
Date: | 2007-05-16 12:03:06 |
Message-ID: | 304157.50040.qm@web31814.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
--- Raimon Fernandez <coder(at)montx(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Raimon Fernandez | 2007-05-16 12:43:59 | Re: aggregate function ? |
Previous Message | Raimon Fernandez | 2007-05-16 07:56:27 | Re: aggregate function ? |