As mentioned above, here is my contrib/tablefunc patch. It includes
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
2002-07-31 00:31:11 +08:00
|
|
|
CREATE OR REPLACE FUNCTION normal_rand(int4, float8, float8, int4)
|
|
|
|
RETURNS setof float8
|
|
|
|
AS 'MODULE_PATHNAME','normal_rand' LANGUAGE 'c' VOLATILE STRICT;
|
|
|
|
|
|
|
|
CREATE VIEW tablefunc_crosstab_2 AS
|
|
|
|
SELECT
|
|
|
|
''::TEXT AS row_name,
|
|
|
|
''::TEXT AS category_1,
|
|
|
|
''::TEXT AS category_2;
|
|
|
|
|
|
|
|
CREATE VIEW tablefunc_crosstab_3 AS
|
|
|
|
SELECT
|
|
|
|
''::TEXT AS row_name,
|
|
|
|
''::TEXT AS category_1,
|
|
|
|
''::TEXT AS category_2,
|
|
|
|
''::TEXT AS category_3;
|
|
|
|
|
|
|
|
CREATE VIEW tablefunc_crosstab_4 AS
|
|
|
|
SELECT
|
|
|
|
''::TEXT AS row_name,
|
|
|
|
''::TEXT AS category_1,
|
|
|
|
''::TEXT AS category_2,
|
|
|
|
''::TEXT AS category_3,
|
|
|
|
''::TEXT AS category_4;
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION crosstab2(text)
|
|
|
|
RETURNS setof tablefunc_crosstab_2
|
|
|
|
AS 'MODULE_PATHNAME','crosstab' LANGUAGE 'c' STABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION crosstab3(text)
|
|
|
|
RETURNS setof tablefunc_crosstab_3
|
|
|
|
AS 'MODULE_PATHNAME','crosstab' LANGUAGE 'c' STABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION crosstab4(text)
|
|
|
|
RETURNS setof tablefunc_crosstab_4
|
|
|
|
AS 'MODULE_PATHNAME','crosstab' LANGUAGE 'c' STABLE STRICT;
|
|
|
|
|
2002-08-15 10:51:27 +08:00
|
|
|
CREATE OR REPLACE FUNCTION crosstab(text,int)
|
|
|
|
RETURNS setof record
|
Attached is an update to contrib/tablefunc. It introduces a new
function, connectby(), which can serve as a reference implementation for
the changes made in the last few days -- namely the ability of a
function to return an entire tuplestore, and the ability of a function
to make use of the query provided "expected" tuple description.
Description:
connectby(text relname, text keyid_fld, text parent_keyid_fld,
text start_with, int max_depth [, text branch_delim])
- returns keyid, parent_keyid, level, and an optional branch string
- requires anonymous composite type syntax in the FROM clause. See
the instructions in the documentation below.
Joe Conway
2002-09-02 13:44:05 +08:00
|
|
|
AS 'MODULE_PATHNAME','crosstab' LANGUAGE 'c' STABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION connectby(text,text,text,text,int,text)
|
|
|
|
RETURNS setof record
|
|
|
|
AS 'MODULE_PATHNAME','connectby_text' LANGUAGE 'c' STABLE STRICT;
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION connectby(text,text,text,text,int)
|
|
|
|
RETURNS setof record
|
|
|
|
AS 'MODULE_PATHNAME','connectby_text' LANGUAGE 'c' STABLE STRICT;
|