X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7961B52924 for ; Fri, 22 Jul 2005 20:39:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36413-06 for ; Fri, 22 Jul 2005 23:39:03 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id A11E15299E for ; Fri, 22 Jul 2005 20:39:02 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j6MNd1kj020304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Jul 2005 17:39:03 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j6MNd0ai053841; Fri, 22 Jul 2005 17:39:00 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j6MNcwCm053840; Fri, 22 Jul 2005 17:38:58 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 22 Jul 2005 17:38:58 -0600 From: Michael Fuhr To: Gnanavel S Cc: Dongsoo Yoon , pgsql-sql@postgresql.org Subject: Re: Error when using array variable Message-ID: <20050722233858.GA47991@winnie.fuhr.org> References: <000601c58e9f$1a3d0cc0$2d216b3d@notebook04> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/204 X-Sequence-Number: 22182 On Fri, Jul 22, 2005 at 03:07:04PM +0530, Gnanavel S wrote: > On 7/22/05, Dongsoo Yoon wrote: > > CREATE OR REPLACE FUNCTION arr_test() > > RETURNS NUMERIC[] AS $BODY$ > > DECLARE > > v_count NUMERIC default 0; > > v_dayIndex NUMERIC default 0; > > t_modifiedTimes NUMERIC[]; > > v_testval NUMERIC default 0; > > .... > > BEGIN > > .... > > for v_count in 1..5 loop > > v_dayIndex := v_dayIndex + 1; > > > t_modifiedTimes[v_dayIndex ] := v_count; > > You need to initialse the array, Otherwise any value added to the array will > be null. This isn't necessary in 8.0, which we can infer is being used because of the dollar quotes. See the 8.0 Release Notes: http://www.postgresql.org/docs/8.0/static/release-8-0.html "Updating an element or slice of a NULL array value now produces a non-NULL array result, namely an array containing just the assigned-to positions." I don't recall if early 8.0 versions had any bugs in this respect, but it does indeed work in 8.0.3. -- Michael Fuhr http://www.fuhr.org/~mfuhr/