From 97140b17c978f8a19c937b0aba5c91f7c45e1145 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Wed, 24 Jun 2015 11:03:16 -0400 Subject: [PATCH] added more flexible output values --- scripts-available/CDB_DistinctMeasure.sql | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts-available/CDB_DistinctMeasure.sql b/scripts-available/CDB_DistinctMeasure.sql index 228a0c7..a5bf1d7 100644 --- a/scripts-available/CDB_DistinctMeasure.sql +++ b/scripts-available/CDB_DistinctMeasure.sql @@ -5,11 +5,11 @@ -- -- -CREATE OR REPLACE FUNCTION CDB_DistinctMeasure ( in_array text[], threshold numeric DEFAULT 0.90 ) RETURNS boolean as $$ +CREATE OR REPLACE FUNCTION CDB_DistinctMeasure ( in_array text[], threshold numeric DEFAULT null ) RETURNS numeric as $$ DECLARE element_count INT4; maxval numeric; - passes boolean; + passes numeric; BEGIN SELECT count(e) INTO element_count FROM ( SELECT unnest(in_array) e ) x; @@ -35,8 +35,11 @@ BEGIN SELECT max(cumsum) maxval FROM b' INTO maxval USING element_count, in_array; - - passes = (maxval >= threshold); + IF threshold is null THEN + passes = maxval; + ELSE + passes = CASE WHEN (maxval >= threshold) THEN 1 ELSE 0 END; + END IF; RETURN passes; END;