Re: stddev returns 0 when there is one row

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Manfred Koizar <mkoi-pg(at)aon(dot)at>, Bruno Wolff III <bruno(at)wolff(dot)to>, pgsql-general(at)postgresql(dot)org
Subject: Re: stddev returns 0 when there is one row
Date: 2003-04-20 04:30:03
Message-ID: 3EA2224B.3030406@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
[PostgreSQL's STDDEV is a sample standard deviation, *not* a population
standrad deviation]
> I don't have a real strong feeling about whether we should change the
> behavior at N=1 or not. Does the SQL200x spec provide any guidance?
>

I guess that's what I get for jumping to conclusions ;-0

The spec does have specific guidance in section
10.9 <aggregate function>:

j) STDDEV_SAMP(X) is equivalent to SQRT(VAR_SAMP(X)).

- and -

viii) If VAR_POP or VAR_SAMP is specified, then let S1 be the sum of
values in the column of TXA, and S2 be the sum of the squares of
the values in the column of TXA.
1) If VAR_POP is specified, then the result is (S2-S1*S1/N)/N.
2) If VAR_SAMP is specified, then:
A) If N is 1 (one), then the result is the null value.
B) Otherwise, the result is (S2-S1*S1/N)/(N-1)

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Brown 2003-04-20 06:28:52 Re: [SQL] Yet Another (Simple) Case of Index not used
Previous Message Tom Lane 2003-04-20 03:34:24 Re: [SQL] Yet Another (Simple) Case of Index not used