Permalink
Browse files

Experimental support for Numeric data type.

  • Loading branch information...
1 parent a65ef1d commit e3b7548f1dc31fa08e76cbe50cf0b1825f0030c3 @tvondra committed Nov 8, 2011
Showing with 587 additions and 0 deletions.
  1. +82 −0 sql/trimmed_aggregates--1.1.sql
  2. +505 −0 src/trimmed.c
@@ -14,6 +14,11 @@ CREATE OR REPLACE FUNCTION trimmed_append_int64(p_pointer internal, p_element bi
AS 'trimmed_aggregates', 'trimmed_append_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_append_numeric(p_pointer internal, p_element numeric, p_cut_low double precision default 0, p_cut_up double precision default 0)
+ RETURNS internal
+ AS 'trimmed_aggregates', 'trimmed_append_numeric'
+ LANGUAGE C IMMUTABLE;
+
/* average */
CREATE OR REPLACE FUNCTION trimmed_avg_double(p_pointer internal)
RETURNS double precision
@@ -30,6 +35,11 @@ CREATE OR REPLACE FUNCTION trimmed_avg_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_avg_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_avg_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_avg_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE avg_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -48,6 +58,12 @@ CREATE AGGREGATE avg_trimmed(bigint, double precision, double precision) (
FINALFUNC = trimmed_avg_int64
);
+CREATE AGGREGATE avg_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_avg_numeric
+);
+
/* variance */
CREATE OR REPLACE FUNCTION trimmed_var_double(p_pointer internal)
RETURNS double precision
@@ -64,6 +80,11 @@ CREATE OR REPLACE FUNCTION trimmed_var_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_var_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_var_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_var_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE var_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -82,6 +103,12 @@ CREATE AGGREGATE var_trimmed(bigint, double precision, double precision) (
FINALFUNC = trimmed_var_int64
);
+CREATE AGGREGATE var_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_numeric
+);
+
/* variance (population estimate) */
CREATE OR REPLACE FUNCTION trimmed_var_pop_double(p_pointer internal)
RETURNS double precision
@@ -98,6 +125,11 @@ CREATE OR REPLACE FUNCTION trimmed_var_pop_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_var_pop_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_var_pop_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_var_pop_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE var_pop_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -116,6 +148,12 @@ CREATE AGGREGATE var_pop_trimmed(bigint, double precision, double precision) (
FINALFUNC = trimmed_var_pop_int64
);
+CREATE AGGREGATE var_pop_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_pop_numeric
+);
+
/* variance (sample estimate) */
CREATE OR REPLACE FUNCTION trimmed_var_samp_double(p_pointer internal)
RETURNS double precision
@@ -132,6 +170,11 @@ CREATE OR REPLACE FUNCTION trimmed_var_samp_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_var_samp_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_var_samp_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_var_samp_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE var_samp_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -150,6 +193,12 @@ CREATE AGGREGATE var_samp_trimmed(bigint, double precision, double precision) (
FINALFUNC = trimmed_var_samp_int64
);
+CREATE AGGREGATE var_samp_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_samp_numeric
+);
+
/* variance */
CREATE OR REPLACE FUNCTION trimmed_stddev_double(p_pointer internal)
RETURNS double precision
@@ -166,6 +215,11 @@ CREATE OR REPLACE FUNCTION trimmed_stddev_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_stddev_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_stddev_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_stddev_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE stddev_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -184,6 +238,12 @@ CREATE AGGREGATE stddev_trimmed(bigint, double precision, double precision) (
FINALFUNC = trimmed_stddev_int64
);
+CREATE AGGREGATE stddev_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_numeric
+);
+
/* variance (population estimate) */
CREATE OR REPLACE FUNCTION trimmed_stddev_pop_double(p_pointer internal)
RETURNS double precision
@@ -200,6 +260,11 @@ CREATE OR REPLACE FUNCTION trimmed_stddev_pop_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_stddev_pop_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_stddev_pop_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_stddev_pop_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE stddev_pop_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -218,6 +283,12 @@ CREATE AGGREGATE stddev_pop_trimmed(bigint, double precision, double precision)
FINALFUNC = trimmed_stddev_pop_int64
);
+CREATE AGGREGATE stddev_pop_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_pop_numeric
+);
+
/* variance (sample estimate) */
CREATE OR REPLACE FUNCTION trimmed_stddev_samp_double(p_pointer internal)
RETURNS double precision
@@ -234,6 +305,11 @@ CREATE OR REPLACE FUNCTION trimmed_stddev_samp_int64(p_pointer internal)
AS 'trimmed_aggregates', 'trimmed_stddev_samp_int64'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION trimmed_stddev_samp_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'trimmed_aggregates', 'trimmed_stddev_samp_numeric'
+ LANGUAGE C IMMUTABLE;
+
CREATE AGGREGATE stddev_samp_trimmed(double precision, double precision, double precision) (
SFUNC = trimmed_append_double,
STYPE = internal,
@@ -250,4 +326,10 @@ CREATE AGGREGATE stddev_samp_trimmed(bigint, double precision, double precision)
SFUNC = trimmed_append_int64,
STYPE = internal,
FINALFUNC = trimmed_stddev_samp_int64
+);
+
+CREATE AGGREGATE stddev_samp_trimmed(numeric, double precision, double precision) (
+ SFUNC = trimmed_append_numeric,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_samp_numeric
);
Oops, something went wrong.

0 comments on commit e3b7548

Please sign in to comment.