mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-18 07:43:24 +02:00
three functions which exercise the tablefunc API. show_all_settings() - returns the same information as SHOW ALL, but as a query result normal_rand(int numvals, float8 mean, float8 stddev, int seed) - returns a set of normally distributed float8 values - This routine implements Algorithm P (Polar method for normal deviates) from Knuth's _The_Art_of_Computer_Programming_, Volume 2, 3rd ed., pages 122-126. Knuth cites his source as "The polar method", G. E. P. Box, M. E. Muller, and G. Marsaglia, _Annals_Math,_Stat._ 29 (1958), 610-611. crosstabN(text sql) - returns a set of row_name plus N category value columns - crosstab2(), crosstab3(), and crosstab4() are defined for you, but you can create additional crosstab functions per directions in the README. Joe Conway
48 lines
3.1 KiB
SQL
48 lines
3.1 KiB
SQL
--
|
|
-- show_all_settings()
|
|
--
|
|
SELECT * FROM show_all_settings();
|
|
|
|
--
|
|
-- normal_rand()
|
|
--
|
|
SELECT * FROM normal_rand(100, 250, 5, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int);
|
|
|
|
--
|
|
-- crosstab()
|
|
--
|
|
create table ct(id serial, rowclass text, rowid text, attribute text, value text);
|
|
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att1','val1');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att2','val2');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att3','val3');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att4','val4');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att1','val5');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att2','val6');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att3','val7');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att4','val8');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att1','val1');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att2','val2');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att3','val3');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att1','val4');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att2','val5');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att3','val6');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
|
|
|