Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f264r0x04693 for ; Mon, 5 Mar 2001 23:53:00 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.122.114.86] (HELO agliodbs.com) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.4.1) with ESMTP id 20836; Mon, 05 Mar 2001 20:52:56 -0800 Message-ID: <3AA46D11.885E1483@agliodbs.com> Date: Mon, 05 Mar 2001 20:52:33 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions X-Mailer: Mozilla 4.73 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 To: Grant , sqllist Subject: Re: How to count elements in an array? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200103/87 X-Sequence-Number: 1735 Grant, The only way I know to enumarate arrays is procedural. This is a good reason to stay away from arrays except in buffer and temporary tables (aside from the fact that array columns violate the relational principle of atomicity). The following sample procedure, paraphrased from Bruce Momjian's book (which you should buy, hint, hint) illustrates enumerating an array of INT4 values: CREATE FUNCTION count_array ( INT4[] ) RETURNS INT2 AS ' DECLARE array_loop INT2; array_col ALIAS FOR $1; BEGIN array_loop := 1; WHILE array_col[array_loop] LOOP array_loop = array_loop + 1; END LOOP; array_loop := array_loop - 1 RETURN array_loop; END;' LANGUAGE 'plpgsql'; -Josh -- ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco