Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,34 @@
-- the minimal table
create table if not exists teststd (n double precision not null);
-- code modularity with view, we could have used a common table expression instead
create view vteststd as
select count(n) as cnt,
sum(n) as tsum,
sum(power(n,2)) as tsqr
from teststd;
-- you can of course put this code into every query
create or replace function std_dev() returns double precision as $$
select sqrt(tsqr/cnt - (tsum/cnt)^2) from vteststd;
$$ language sql;
-- test data is: 2,4,4,4,5,5,7,9
insert into teststd values (2);
select std_dev() as std_deviation;
insert into teststd values (4);
select std_dev() as std_deviation;
insert into teststd values (4);
select std_dev() as std_deviation;
insert into teststd values (4);
select std_dev() as std_deviation;
insert into teststd values (5);
select std_dev() as std_deviation;
insert into teststd values (5);
select std_dev() as std_deviation;
insert into teststd values (7);
select std_dev() as std_deviation;
insert into teststd values (9);
select std_dev() as std_deviation;
-- cleanup test data
delete from teststd;