Обсуждение: multidimensional arrays

Поиск
Список
Период
Сортировка

multidimensional arrays

От
Ketema
Дата:
Is it possible to access a subarray of a multi dimensional array as a
whole?

example:

'{
    {
        {1,2,3}, {11,22,33}, {111,222,333}
    },
    {
        {4,5,6}, {44,55,66}, {444,555,666}
    },
    {
        {7,8,9}, {77,88,99}, {777,888,999}
    }
}' --pretend this is _intarray

if wanted to do:
 select case when 1 = any(_intarray[1][1]) then true else false end;

this should be equivalent to:
 select case when 1 in (1,2,3) then true else false end;

the first statement produces an error about target of any must be an
array.  If I try to cast to integer[] i get an error stating that
integer cant be cast to integer[]

Thanks!


Re: multidimensional arrays

От
Tom Lane
Дата:
Ketema <ketema@gmail.com> writes:
> Is it possible to access a subarray of a multi dimensional array as a
> whole?

I think you want an array slice (ie, something with some colons in the
subscripts).  See the manual:
http://www.postgresql.org/docs/8.2/static/arrays.html

            regards, tom lane

Re: multidimensional arrays

От
Ketema
Дата:
On May 1, 10:48 pm, t...@sss.pgh.pa.us (Tom Lane) wrote:
> Ketema <ket...@gmail.com> writes:
> > Is it possible to access a subarray of a multi dimensional array as a
> > whole?
>
> I think you want an array slice (ie, something with some colons in the
> subscripts).  See the manual:http://www.postgresql.org/docs/8.2/static/arrays.html
>
>                         regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majord...@postgresql.org so that your
>        message can get through to the mailing list cleanly

OK, sorry I missed that.  still not sure I understand even after
reading that.

for my above example I would then use:

select case when 1 = any(_intarray[1:1][1:1]) then true else false
end; ?

and it should return true since a 1 exists in that first subarray?

thanks