[Collab-qa-commits] r1456 - udd/sql
Andreas Tille
tille at alioth.debian.org
Fri May 8 20:23:14 UTC 2009
Author: tille
Date: 2009-05-08 20:23:13 +0000 (Fri, 08 May 2009)
New Revision: 1456
Added:
udd/sql/array_accum.sql
Log:
Create comma aggregate function
Added: udd/sql/array_accum.sql
===================================================================
--- udd/sql/array_accum.sql (rev 0)
+++ udd/sql/array_accum.sql 2009-05-08 20:23:13 UTC (rev 1456)
@@ -0,0 +1,29 @@
+/******************************************************************************
+ * Sometimes it is practical to aggregate a collumn to a comma separated list *
+ * This is described at: *
+ * *
+ * http://www.zigo.dhs.org/postgresql/#comma_aggregate *
+ * *
+ ******************************************************************************/
+
+CREATE AGGREGATE array_accum (anyelement) (
+ sfunc = array_append,
+ stype = anyarray,
+ initcond = '{}'
+);
+
+/*****************************************************************************
+ * this can be used like this: *
+ * array_to_string(array_accum(column),',') *
+ * Example: *
+ * *
+ SELECT av.version, array_to_string(array_accum(architecture),',') FROM
+ ( SELECT architecture AS architecture, version FROM packages
+ WHERE package = 'gcc' GROUP BY architecture, version ORDER BY architecture
+ ) AS av
+ GROUP BY version ORDER BY version DESC;
+ * *
+ *****************************************************************************/
+
+
+
More information about the Collab-qa-commits
mailing list