X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4F01A476291 for ; Tue, 4 Mar 2003 14:41:42 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 85976-04 for ; Tue, 4 Mar 2003 14:41:38 -0500 (EST) Received: from joeconway.com (63-210-180-150.skyriver.net [63.210.180.150]) by postgresql.org (Postfix) with ESMTP id 6AAA547628E for ; Tue, 4 Mar 2003 14:41:38 -0500 (EST) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.4) with ESMTP-TLS id 1627728; Tue, 04 Mar 2003 12:17:20 -0800 Message-ID: <3E6500F4.8030700@joeconway.com> Date: Tue, 04 Mar 2003 11:39:32 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Guy Fraser Cc: pgsql-sql@postgresql.org Subject: Re: Convert a text list to text array? Was: Denormalizing during References: <200302241433.49502.josh@agliodbs.com> <3E64E93D.9050506@incentre.net> In-Reply-To: <3E64E93D.9050506@incentre.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/130 X-Sequence-Number: 12170 Guy Fraser wrote: > The email at the bottom gave me an idea, but it doesn't quite work: > > CREATE AGGREGATE accumulate( > BASETYPE = text, > SFUNC = textcat, > STYPE = text, > INITCOND = '' ); > -- > SELECT ('{' || ltrim(accumulate(',' || tablename),',') || '}') as cruft > FROM pg_tables > WHERE hasindexes = 'f'; > > cruft > --------------------------- > {pg_xactlock,pg_listener} > (1 row) > > This produces somthing that looks like it could be able to be converted > into an array but I cant figure out how to make it work. > If I understand correctly, the function array_accum() distributed with PL/R can do exactly what you're looking for (you need the function, but you don't necessarily need to use PL/R): CREATE OR REPLACE FUNCTION array_accum (_name, name) RETURNS name[] AS '$libdir/plr','array_accum' LANGUAGE 'C'; CREATE AGGREGATE accumulate ( sfunc = array_accum, basetype = name, stype = _name ); regression=# SELECT accumulate(tablename) as cruft FROM pg_tables WHERE tablename LIKE 'c%'; cruft --------------------------------------- {connectby_int,connectby_text,ct,cth} (1 row) See: http://www.joeconway.com/plr/doc/plr-aggregate-funcs.html and download at: http://www.joeconway.com/plr/ HTH, Joe