Re: [REPOST] plpgsql : looping over multidimensional array : getting NULL for subdimension

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Samba <saasira(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [REPOST] plpgsql : looping over multidimensional array : getting NULL for subdimension
Date: 2010-12-01 20:34:51
Message-ID: AANLkTimwDXq-y8jf2W2hMHnmkh4dbG3XHYRhefFydRZ4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 1, 2010 at 10:51 AM, Samba <saasira(at)gmail(dot)com> wrote:
> Hi all,
>
> I'm trying to loop over a multidimensional array and find if any of the
> elements in a sub-dimensional array are matching some known criteria but
> facing issue with NULL for the sub arrays.
>
> I have a data structure that looks like:
>
>    some_array VARCHAR[][] :=
> '{{samba,sarath,sreenivas},{samba,mukhesh,pavan}}';
>
> I'm trying to assign the individual sub arrays to other array elements like:
>
>   other-array VARCHAR[];
>
>   other_array=some_array[1];
>
> and I'm expecting to get '{samba,sarath,sreenivas}' for index 1 and
> {samba,mukhesh,pavan} for index 2;
> however, I'm getting NULL.
>
> Can some one explain the way I can assign subarrays to other array elements
> plpgsql?

There is no truly effective way to do that. you can however slice the
array which is almost as good:
other_array=some_array[1:1];
note this will give {{samba,sarath,sreenivas}}, not {samba,sarath,sreenivas}

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2010-12-01 20:46:59 Re: How to find correct locale name for CREATE DATABASE
Previous Message James B. Byrne 2010-12-01 20:28:25 PG84 and SELinux