| From: | Markus Neumann <markus(at)neumann(dot)ch> | 
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org | 
| Subject: | Re: I probably don't understand aggregates. | 
| Date: | 2014-06-11 22:23:40 | 
| Message-ID: | 5398D6EC.9010508@neumann.ch | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-novice | 
On 12.06.2014 00:09, Tom Lane wrote:
> That is certainly not going to do what you presumably want. The outer 
> query doesn't think that the wrapper function is an aggregate; it's 
> just a plain scalar function that will be called separately on each 
> row of the table. Meanwhile, the best way to think about what's 
> happening inside the wrapper is that M := myAggrFunction(x); is 
> equivalent to SELECT myAggrFunction(x) INTO M FROM 
> anonymous-one-row-table; or if you're an Oracle refugee, SELECT 
> myAggrFunction(x) INTO M FROM dual; So the aggregate is evaluated over 
> just one row, and I suppose the zero-divide error happens because your 
> final function is failing to cope with that case. regards, tom lane 
On 12.06.2014 00:08, David G Johnston wrote:
> Because myWrapperFunction is not an aggregate you end up calling 
> myAggr three times, once each with for the values 0, 0, 1. The way 
> myAggr is written if the final state of the function is 0 a division 
> by zero will occur. My privately noted confusion about the lack of a 
> GROUP BY still applies - I just forgot about the implicit GROUP BY 
> when all output columns are defined using aggregates. Try executing: 
> SELECT myAggr(x), x FROM test GROUP BY x; This is basically what you 
> are doing when you put the aggregate into the wrapper. David J. -- 
> View this message in context: 
> http://postgresql.1045698.n5.nabble.com/I-probably-don-t-understand-aggregates-tp5806879p5806896.html 
> Sent from the PostgreSQL - novice mailing list archive at Nabble.com. 
Thank you both, that helped a lot.
I'm doing a project for my informatics minor, where I have to use 
aggregates to get some matrix multiplication and inversion done inside 
pgsql.
But how can I get my wrapper function to evaluate the aggregate on the 
whole table and work with the result afterwards?
Or do I need to change the aggregate?
Markus
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G Johnston | 2014-06-11 22:34:02 | Re: I probably don't understand aggregates. | 
| Previous Message | Tom Lane | 2014-06-11 22:09:33 | Re: I probably don't understand aggregates. |