Skip to content

Commit

Permalink
Update functions.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
garysieling committed Sep 22, 2015
1 parent 2644108 commit a62b15e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions functions.sql
Expand Up @@ -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$;

0 comments on commit a62b15e

Please sign in to comment.