X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 83FDECCA99 for ; Thu, 17 Jul 2003 17:51:35 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 23565-04 for ; Thu, 17 Jul 2003 17:52:03 +0000 (GMT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 061A8CCA83 for ; Thu, 17 Jul 2003 14:51:33 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1826496; Thu, 17 Jul 2003 10:18:03 -0700 Message-ID: <3F16E1D5.7080304@joeconway.com> Date: Thu, 17 Jul 2003 10:50:13 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Donald Fraser Cc: "[ADMIN]" Subject: Re: Arrays in pl/pgsql functions References: <005701c34c55$8d017540$1664a8c0@DEMOLITION> In-Reply-To: <005701c34c55$8d017540$1664a8c0@DEMOLITION> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/151 X-Sequence-Number: 9491 Donald Fraser wrote: > Could someone be please inform me what the correct syntax for accessing arrays > is or tell me if its not possible with pl/pgSQL functions. > It won't work in 7.3.x or before, as you've noted. In 7.4 this will work: CREATE OR REPLACE FUNCTION test_arrays() RETURNS int4[] AS ' DECLARE test int4[] := ''{}''; BEGIN test[1] := 1; RETURN test; END ' LANGUAGE 'plpgsql'; regression=# select test_arrays(); test_arrays ------------- {1} (1 row) Note that you have to initialize "test" to an empty array, because otherwise you are trying to add an element to a NULL::int4[], the result of which is still NULL. Joe