Re: stddev returns 0 when there is one row - Mailing list pgsql-general

From Tom Lane
Subject Re: stddev returns 0 when there is one row
Date
Msg-id 18667.1050974816@sss.pgh.pa.us
Whole thread Raw
In response to Re: stddev returns 0 when there is one row  (nolan@celery.tssi.com)
List pgsql-general
nolan@celery.tssi.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


pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: Documentation
Next
From: Tom Lane
Date:
Subject: Re: postgresql doesn't start