added CDB_Math_mode
This commit is contained in:
parent
41a2c7363e
commit
723a08e814
4
NEWS
4
NEWS
@ -1,3 +1,7 @@
|
|||||||
|
0.3.X (2014-XX-XX)
|
||||||
|
------------------
|
||||||
|
Added CDB_Math_Mode function
|
||||||
|
|
||||||
0.3.6 (2014-08-11)
|
0.3.6 (2014-08-11)
|
||||||
------------------
|
------------------
|
||||||
Dummy release to solve some issues with cdb branch/tag
|
Dummy release to solve some issues with cdb branch/tag
|
||||||
|
26
scripts-available/CDB_Math.sql
Normal file
26
scripts-available/CDB_Math.sql
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
-- CartoDB Math SQL functions
|
||||||
|
|
||||||
|
|
||||||
|
-- Mode
|
||||||
|
-- https://wiki.postgresql.org/wiki/Aggregate_Mode
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cartodb._CDB_Math_final_mode(anyarray)
|
||||||
|
RETURNS anyelement AS
|
||||||
|
$BODY$
|
||||||
|
SELECT a
|
||||||
|
FROM unnest($1) a
|
||||||
|
GROUP BY 1
|
||||||
|
ORDER BY COUNT(1) DESC, 1
|
||||||
|
LIMIT 1;
|
||||||
|
$BODY$
|
||||||
|
LANGUAGE 'sql' IMMUTABLE;
|
||||||
|
|
||||||
|
DROP AGGREGATE IF EXISTS cartodb.CDB_Math_Mode(anyelement);
|
||||||
|
|
||||||
|
CREATE AGGREGATE cartodb.CDB_Math_Mode(anyelement) (
|
||||||
|
SFUNC=array_append,
|
||||||
|
STYPE=anyarray,
|
||||||
|
FINALFUNC=_CDB_Math_final_mode,
|
||||||
|
INITCOND='{}'
|
||||||
|
);
|
||||||
|
|
1
scripts-enabled/220-CDB_Math.sql
Symbolic link
1
scripts-enabled/220-CDB_Math.sql
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../scripts-available/CDB_Math.sql
|
4
test/CDB_MathTest.sql
Normal file
4
test/CDB_MathTest.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
SELECT cdb_math_mode(a) from unnest(ARRAY[1,2,2,3]) a;
|
||||||
|
SELECT cdb_math_mode(a) from unnest(ARRAY[1,2,3]) a;
|
||||||
|
SELECT cdb_math_mode(a) from unnest(ARRAY[1]) a;
|
3
test/CDB_MathTest_expect
Normal file
3
test/CDB_MathTest_expect
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
2
|
||||||
|
1
|
||||||
|
1
|
Loading…
Reference in New Issue
Block a user