Re: stddev returns 0 when there is one row

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: nolan(at)celery(dot)tssi(dot)com
Cc: pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Re: stddev returns 0 when there is one row
Date: 2003-04-22 01:26:56
Message-ID: 18667.1050974816@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

nolan(at)celery(dot)tssi(dot)com writes:
> wouldn't the easiest way to offer both sample and population formulas for
> variance and standard deviation be to just add two new functions,
> varp and stddevp, most of the code for which already exists?

As Joe pointed out, SQL200x seems to have laid down the law already on
what to call these things.

> That way they remain single-input aggregates.

My comment about multiple inputs was in response to the suggestion of
grouped input, which I took to mean that you'd want to write something
like "SELECT STDDEV_GROUPED(value, num_occurrences) FROM foo".

You could hack your way around the problem by defining the aggregate
to take a two-element array type:
SELECT STDDEV_GROUPED(ARRAY[value, num_occurrences]) FROM foo
but this seems ugly and inefficient.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-22 01:28:36 Re: postgresql doesn't start
Previous Message Joe Conway 2003-04-22 00:48:42 Re: Documentation