Re: Calculating product from rows - (aggregate product )

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dennis Brakhane <brakhane(at)googlemail(dot)com>
Cc: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>, pgsql-general(at)postgresql(dot)org
Subject: Re: Calculating product from rows - (aggregate product )
Date: 2009-05-04 23:51:39
Message-ID: 20848.1241481099@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dennis Brakhane <brakhane(at)googlemail(dot)com> writes:
> On Mon, May 4, 2009 at 12:53 PM, Jasen Betts <jasen(at)xnet(dot)co(dot)nz> wrote:
>> select exp(sum(ln( thiscolumn ))) from foo;

> Keep in mind that it won't work when the table containts negative
> numbers, though (or zeros, but since in this case the product is also
> zero, it doesn't matter)

Its numerical stability probably leaves something to be desired, too...
but it is a cute solution.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moseley 2009-05-05 00:42:57 Re: Tracking down a deadlock
Previous Message Martijn van Oosterhout 2009-05-04 22:04:42 Re: Calculating product from rows - (aggregate product )