X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C45049DCB62 for ; Mon, 27 Mar 2006 09:48:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63394-01 for ; Mon, 27 Mar 2006 09:48:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 7978B9DCA1F for ; Mon, 27 Mar 2006 09:48:29 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 6D8F256408; Mon, 27 Mar 2006 07:48:33 -0600 (CST) Received: (hashcash-sendmail, from uid 1001); Mon, 27 Mar 2006 07:48:31 -0600 Date: Mon, 27 Mar 2006 07:48:31 -0600 From: "Jim C. Nasby" To: PFC Cc: Don Maier , pgsql-sql@postgresql.org Subject: Re: Expressing a result set as an array (and vice versa)? Message-ID: <20060327134831.GJ80726@pervasive.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060327:lists@peufeu.com::D1nmeN7xlLFQwqOW:05+FN X-Hashcash: 1:20:060327:dmaier@genome.stanford.edu::jMh8P921kCHT60pw:00000000000 0000000000000000000000002UTT X-Hashcash: 1:20:060327:pgsql-sql@postgresql.org::EOngTUGZwYkgtDMT:0000000000000 000000000000000000000000B3Yp X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108, UPPERCASE_25_50=0] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200603/415 X-Sequence-Number: 24761 On Sat, Mar 25, 2006 at 12:17:08AM +0100, PFC wrote: > > > CREATE OR REPLACE FUNCTION foreach( liste INTEGER[] ) RETURNS SETOF > INTEGER AS $$ > DECLARE > i INTEGER; > BEGIN > FOR i IN 1..icount(liste) LOOP > RETURN NEXT liste[i]; > END LOOP; > END; > $$ LANGUAGE plpgsql; Seems like this should really exist in the backend... > CREATE AGGREGATE array_accum ( > sfunc = array_append, > basetype = anyelement, > stype = anyarray, > initcond = '{}' > ); > > SELECT array_accum( DISTINCT list_id ) FROM bookmarks; > array_accum > --------------- > {1,2,3,4,5,7} Couldn't you just use array()? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461