From a62b15e732b848646760c81c8c324d6e3c7e19ef Mon Sep 17 00:00:00 2001 From: Gary Sieling Date: Mon, 21 Sep 2015 20:21:26 -0400 Subject: [PATCH] Update functions.sql --- functions.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/functions.sql b/functions.sql index aa5a9e5..c099809 100644 --- a/functions.sql +++ b/functions.sql @@ -4,3 +4,14 @@ CREATE AGGREGATE flatMap (anyarray) stype = ANYARRAY, initcond = '{}' ); + +-- http://stackoverflow.com/questions/3994556/eliminate-duplicate-array-values-in-postgres +CREATE OR REPLACE FUNCTION uniq (ANYARRAY) RETURNS ANYARRAY +LANGUAGE SQL +AS $body$ + SELECT ARRAY( + SELECT DISTINCT $1[s.i] + FROM generate_series(array_lower($1,1), array_upper($1,1)) AS s(i) + ORDER BY 1 + ); +$body$;