Note that the example aggregate array_accum is comparable to the now
authorTom Lane
Thu, 20 Nov 2008 21:10:44 +0000 (21:10 +0000)
committerTom Lane
Thu, 20 Nov 2008 21:10:44 +0000 (21:10 +0000)
built-in array_agg.  Per suggestion from Robert Haas.

doc/src/sgml/xaggr.sgml

index dce8d8f1caa11beb9a3e052aab990ab93322264d..3c4ce19258e9e75a9a90d67fd734e39a17c9de12 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
  
   User-Defined Aggregates
@@ -9,7 +9,7 @@
   
 
   
-   Aggregate functions  in PostgreSQL 
+   Aggregate functions  in PostgreSQL
    are expressed in terms of state values
    and state transition functions.
    That is, an aggregate operates using a state value that is updated
@@ -41,7 +41,7 @@
    aggregate to work on a data type for complex numbers,
    we only need the addition function for that data type.
    The aggregate definition would be:
-   
+
 
 CREATE AGGREGATE sum (complex)
 (
@@ -80,7 +80,7 @@ SELECT sum(a) FROM test_complex;
    the transition function is marked strict (i.e., not to be called
    for null inputs).
   
-  
+
   
    Another bit of default behavior for a strict transition function
    is that the previous state value is retained unchanged whenever a
@@ -89,7 +89,7 @@ SELECT sum(a) FROM test_complex;
    transition function as strict; instead code it to test for null inputs and
    do whatever is needed.
   
-  
+
   
    avg (average) is a more complex example of an aggregate.
    It requires
@@ -132,7 +132,10 @@ CREATE AGGREGATE array_accum (anyelement)
 
 
    Here, the actual state type for any aggregate call is the array type
-   having the actual input type as elements.
+   having the actual input type as elements.  The behavior of the aggregate
+   is to concatenate all the inputs into an array of that type.
+   (Note: the built-in aggregate array_agg provides similar
+   functionality, with better performance than this definition would have.)
   
 
   
@@ -149,14 +152,14 @@ SELECT attrelid::regclass, array_accum(attname)
  pg_tablespace | {spcname,spcowner,spclocation,spcacl}
 (1 row)
 
-SELECT attrelid::regclass, array_accum(atttypid)
+SELECT attrelid::regclass, array_accum(atttypid::regtype)
     FROM pg_attribute
     WHERE attnum > 0 AND attrelid = 'pg_tablespace'::regclass
     GROUP BY attrelid;
 
-   attrelid    |   array_accum   
----------------+-----------------
- pg_tablespace | {19,26,25,1034}
+   attrelid    |        array_accum        
+---------------+---------------------------
+ pg_tablespace | {name,oid,text,aclitem[]}
 (1 row)