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 3C6DF9DCDD3 for ; Fri, 24 Mar 2006 19:16:25 -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 76956-03 for ; Fri, 24 Mar 2006 19:16:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id BD05B9DC847 for ; Fri, 24 Mar 2006 19:16:22 -0400 (AST) Received: (qmail 30535 invoked from network); 25 Mar 2006 00:17:09 +0100 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 25 Mar 2006 00:17:09 +0100 To: "Don Maier" , pgsql-sql@postgresql.org Subject: Re: Expressing a result set as an array (and vice versa)? References: Message-ID: Date: Sat, 25 Mar 2006 00:17:08 +0100 From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200603/403 X-Sequence-Number: 24749 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; 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} SELECT * FROM foreach( '{1,2,3,4,5,7}' ); foreach --------- 1 2 3 4 5 7 On Thu, 23 Mar 2006 20:44:32 +0100, Don Maier wrote: > Good day, > > Is it possible to construct an array from an appropriate select > expression that generates a result set of unknown cardinality? > To focus on the simple case: Is it possible to construct a one- > dimensional array from a select of a single column in a table with an > unknown number of rows? > > Conversely, is it possible to construct a (single column) result set > from a select expression on a one-dimensional array with an unknown > number of elements? > > Thanks for any hints! > > Regards, > Don Maier > > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly