X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id 39278CCAAA for ; Thu, 17 Jul 2003 18:08:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 72129-09 for ; Thu, 17 Jul 2003 18:08:20 +0000 (GMT) Received: from gsy_sbs_1.cisx.com (unknown [213.133.202.58]) by svr1.postgresql.org (Postfix) with ESMTP id 1397BCCAA8 for ; Thu, 17 Jul 2003 15:07:50 -0300 (ADT) Received: from DEMOLITION ([192.168.100.22]) by gsy_sbs_1.cisx.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id PCH9J125; Thu, 17 Jul 2003 18:59:10 +0100 Message-ID: <00ab01c34c8e$ba682400$1664a8c0@DEMOLITION> From: "Donald Fraser" To: "[ADMIN]" References: <005701c34c55$8d017540$1664a8c0@DEMOLITION> <3F16E1D5.7080304@joeconway.com> Subject: Re: Arrays in pl/pgsql functions Date: Thu, 17 Jul 2003 19:10:33 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4927.1200 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/152 X-Sequence-Number: 9492 Many thanks for clearing that one up. I have avoided using arrays for the mean time and gone for the more elegant solution of using an additional table. More flexible and powerful but, in the simple case that I needed, meant more work... Roll on 7.4 ! Regards Donald Fraser. ----- Original Message ----- From: "Joe Conway" To: "Donald Fraser" Cc: "[ADMIN]" Sent: Thursday, July 17, 2003 6:50 PM Subject: Re: [ADMIN] Arrays in pl/pgsql functions > 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 > >