From 00ccbefbc7414fed4547d40ee3f5964da13268c6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 8 Nov 2013 08:36:53 +0100 Subject: [PATCH] Add postgresql function for access to pickle tags array and aggregate it. --- sql/tags.sql | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sql/tags.sql diff --git a/sql/tags.sql b/sql/tags.sql new file mode 100644 index 00000000..368d0b28 --- /dev/null +++ b/sql/tags.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE FUNCTION unpickle (data text) + RETURNS text[] +AS $$ + import base64 + import pickle + + return pickle.loads(base64.b64decode(data)) +$$ LANGUAGE plpythonu; + +CREATE OR REPLACE FUNCTION array_uniq_join (data text[], data2 text[]) + RETURNS text[] +AS $$ + tmp = set(data) + tmp.update(data2) + return tuple(tmp) +$$ LANGUAGE plpythonu; + +DROP AGGREGATE array_uniq_concat (text[]); +CREATE AGGREGATE array_uniq_concat (text[]) +( + sfunc = array_uniq_join, + stype = text[], + initcond = '{}' +);