X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 87A4BD1B174 for ; Fri, 30 Jul 2004 15:46:32 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68382-09 for ; Fri, 30 Jul 2004 18:46:29 +0000 (GMT) Received: from mail.sells.com (mail.sells.com [204.107.136.10]) by svr1.postgresql.org (Postfix) with ESMTP id 34C31D1B173 for ; Fri, 30 Jul 2004 15:46:26 -0300 (ADT) Received: from [192.168.5.55] (192.168.5.55) by mail.sells.com with ESMTP (Eudora Internet Mail Server 3.2.5) for ; Fri, 30 Jul 2004 13:46:26 -0500 Mime-Version: 1.0 X-Sender: aspeitia@mail.int.sells.com Message-Id: Date: Fri, 30 Jul 2004 13:46:36 -0500 To: pgsql-sql@postgresql.org From: Ray Aspeitia Subject: How to create an aggregate? Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/244 X-Sequence-Number: 18496 Not sure if this made it through before I subscribed, so... Hello all, before I ask, this is what I have done so far: -- created this new aggregate function CREATE AGGREGATE groupconcat_array ( SFUNC = array_append, BASETYPE = anyelement, STYPE = anyarray, initcond = '{}' ); -- ran this select statement SELECT array_to_string(groupconcat_array(oa.order_number), '|') ... output is text : 46952|46953|46954|46955|46949 What I would like to do is just have 1 function that does the same thing like: SELECT groupjoin('|', field2) FROM mytable GROUP BY field1 with the same output as my current implementation. I tried doing that with the CREATE AGGREGATE in conjunction with the FINALFUNC parameter set to array_to_string, but array_to_string needs 2 parameters to function. and I do not know the reference name of the STYPE variable while it is in the aggregate function to pass to it. I also would like to pass the delimiter to the aggregate as a parameter and I am not sure if it can handle that. I know that this is just being picky, but any insight would be appreciated. Thanks. Ray A. --