Thread: Bidimensional Array

Bidimensional Array

From
Leandro Guimarães
Date:
Hello Everyone,
  Please, could someone help me with the following problem?

  I need to get a bidimensional array from a postgresql function, everything is working fine with the driver version 8.2 bellow, put when i upgraded to 9.x the .getArray() method is not working anymore, i always have the message: No results were returned by the query.

  Following my code and my exception with the comments, please i'm crazy searching for a answer for this problem:

....

Array arr = rs.getArray(1); //checking the array, i'ts possible to see the elements "{"{319.1,811.2,915.5}"}"
ResultSet arrRS = arr.getResultSet();
while (arrRS.next()) {                    
     Array a1 = arrRS.getArray(2); //checking the array, i'ts possible to see the elements {319.1,811.2,915.5}                                         
     String[] str = (String[]) a1.getArray(); //HERE HAPPENS THE EXCEPTION

}

...

Following the exception

rg.postgresql.util.PSQLException: No results were returned by the query.
    at org.postgresql.jdbc2.TypeInfoCache.getPGArrayElement(TypeInfoCache.java:390)
    at org.postgresql.jdbc2.AbstractJdbc2Array.buildArray(AbstractJdbc2Array.java:323)
    at org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:149)
    at org.postgresql.jdbc2.AbstractJdbc2Array.getArray(AbstractJdbc2Array.java:115)


Thanks!
Leandro Guimarães


Re: Bidimensional Array

From
Kris Jurka
Date:

On Mon, 26 Dec 2011, Leandro Guimar?es wrote:

>   I need to get a bidimensional array from a postgresql function, everything
> is working fine with the driver version 8.2 bellow, put when i upgraded to
> 9.x the .getArray() method is not working anymore, i always have the
> message: No results were returned by the query.
>

What is the datatype of the column?

Kris Jurka

Re: Bidimensional Array

From
Kris Jurka
Date:
On 12/26/2011 12:23 PM, Leandro Guimarães wrote:
> Hello Kris,
>    thanks for your answer. The dataType is varchar.
>
>    I did a workaround to solve the problem, but i'm sure it's not a good
> approach.
>
>    I'm using the a1.toString() method and using .split by comma to break
> the value and return the String[]
>

Your problem is that you don't really have a two dimensional array.  You
have a one dimensional array whose contents look similar to an array,
but are actually just a string of text.

jurka=# select array_ndims('{"{319.1,811.2,915.5}"}'::varchar[]);
  array_ndims
-------------
            1


Those interior quotes are not correct.

jurka=# select array_ndims('{{319.1,811.2,915.5}}'::varchar[]);
  array_ndims
-------------
            2

jurka=# select ('{{319.1,811.2,915.5}}'::varchar[])[1][1];
  varchar
---------
  319.1

Kris Jurka