Обсуждение: reading an oidvector field error

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

reading an oidvector field error

От
Takeichi Kanzaki Cabrera
Дата:
Hi:
I need to read from the database a oidvector field, I'm using this
code snipped to do this:

            Array argsList = rsFunc.getArray("field");
            ResultSet rsArgs = argsList.getResultSet();
            while (rsArgs.next()) {
                String s = rsArgs.getInt(2);    //get an error here.
                PgDataType type = this.getDataType(s);
                args.add(type);
            }
rsFunc: is the ResultSet to read the data.
argsList: is and java.sql.Array.

but I get an error of execution time on the line signed, I'm check the
driver source code and I find that this kind of vector is not
supported and I can't change the data type of the field.
Could some one help me to solve this.

--
My regards,
Takeichi Kanzaki Cabrera
Profesor of Computer Programming Techniques and Database Systems
University of Holguin
Cuba

Re: reading an oidvector field error

От
Oliver Jowett
Дата:
Takeichi Kanzaki Cabrera wrote:

> but I get an error of execution time on the line signed,

What is the exact error that you get?

-O

Re: reading an oidvector field error

От
Takeichi Kanzaki Cabrera
Дата:
Here is the exception and the stack trace that I get:
org.postgresql.util.PSQLException: Method
org.postgresql.jdbc3.Jdbc3Array.getArrayImpl(long,int,Map) is not yet
implemented.
        at org.postgresql.Driver.notImplemented(Driver.java:580)
        at org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:232)
        at org.postgresql.jdbc2.AbstractJdbc2Array.getResultSetImpl(AbstractJdbc2Array.java:291)
        at org.postgresql.jdbc2.AbstractJdbc2Array.getResultSet(AbstractJdbc2Array.java:252)
        at pgObjects.PgDatabase.loadFunctionsFromDatabase(PgDatabase.java:893)
        at test.Test.showFunctions(Test.java:134)
        at test.Test.main(Test.java:166)

Takeichi.

Re: reading an oidvector field error

От
Oliver Jowett
Дата:
Takeichi Kanzaki Cabrera wrote:
> Here is the exception and the stack trace that I get:
> org.postgresql.util.PSQLException: Method
> org.postgresql.jdbc3.Jdbc3Array.getArrayImpl(long,int,Map) is not yet
> implemented.
>         at org.postgresql.Driver.notImplemented(Driver.java:580)
>         at org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:232)
>         at org.postgresql.jdbc2.AbstractJdbc2Array.getResultSetImpl(AbstractJdbc2Array.java:291)
>         at org.postgresql.jdbc2.AbstractJdbc2Array.getResultSet(AbstractJdbc2Array.java:252)
>         at pgObjects.PgDatabase.loadFunctionsFromDatabase(PgDatabase.java:893)

This stacktrace doesn't match the line in your code you claim throws an
exception. You originally said:

>             Array argsList = rsFunc.getArray("field");
>             ResultSet rsArgs = argsList.getResultSet();
>             while (rsArgs.next()) {
>                 String s = rsArgs.getInt(2);    //get an error here.
>                 PgDataType type = this.getDataType(s);
>                 args.add(type);
>             }

but the code path your stacktrace shows is throwing an exception on
getResultSet().

Can you clarify what the code that actually causes the error is?

However the most likely cause is that the array code just does not
understand the OID type -- there is this code in getArrayImpl when an
unsupported array element type is encountered:

>>         default:
>>             if (conn.getLogger().logDebug())
>>                 conn.getLogger().debug("getArrayImpl(long,int,Map) with "+getBaseTypeName());
>>             throw org.postgresql.Driver.notImplemented(this.getClass(), "getArrayImpl(long,int,Map)");

(this should really throw a more informative exception..)

You could use getString() and parse the array representation yourself as
a workaround, or teach the driver's array code about oids.

-O

Re: reading an oidvector field error

От
Tom Lane
Дата:
Oliver Jowett <oliver@opencloud.com> writes:
> However the most likely cause is that the array code just does not
> understand the OID type -- there is this code in getArrayImpl when an
> unsupported array element type is encountered:

Another problem is that oidvector is not the same as oid[] --- for what
are now entirely historical reasons, they have different external
representations, which is certainly going to confuse any client-side
code trying to parse the data.  You'd really need some single-purpose
code in the driver to handle oidvector at all.

In very recent PG releases, you could cast oidvector to oid[] (or maybe
better int8[]) in your query, but unless the JDBC array code copes with
nondefault subscripts, it'll still have trouble:

regression=# select '1 2 3'::oidvector::int8[];
     int8
---------------
 [0:2]={1,2,3}
(1 row)

regression=#

            regards, tom lane

Re: reading an oidvector field error

От
Kris Jurka
Дата:

On Mon, 16 Jan 2006, Tom Lane wrote:

> In very recent PG releases, you could cast oidvector to oid[] (or maybe
> better int8[]) in your query, but unless the JDBC array code copes with
> nondefault subscripts, it'll still have trouble:
>

The JDBC array code throws away nondefault subscripts because the JDBC
spec says that all arrays are 1-indexed.  For the most part people don't
want non-default subscripts and only get them via prepending operations
that they didn't expect to alter the indexing (of course these are now
gone in 8.2).

Kris Jurka

Re: reading an oidvector field error

От
Tom Lane
Дата:
Kris Jurka <books@ejurka.com> writes:
> On Mon, 16 Jan 2006, Tom Lane wrote:
>> In very recent PG releases, you could cast oidvector to oid[] (or maybe
>> better int8[]) in your query, but unless the JDBC array code copes with
>> nondefault subscripts, it'll still have trouble:

> The JDBC array code throws away nondefault subscripts because the JDBC
> spec says that all arrays are 1-indexed.

OK, so casting to int8[] in the query should be a usable workaround.
(You want int8 not int4 because OIDs are unsigned and won't necessarily
fit in an int4.)

            regards, tom lane

Re: reading an oidvector field error

От
Takeichi Kanzaki Cabrera
Дата:
I solve the problem by getting the field as a String and implementing
a simple parser for the result.
All the ways I test the choice of cast the field as a int8[] and get
this exception:

java.sql.SQLException: ERROR: cannot cast type oidvector to bigint[]
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1482)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1267)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:186)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:392)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:314)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:221)
        at pgObjects.PgServer.executeQuery(PgServer.java:372)
        at pgObjects.PgDatabase.loadFunctionsFromDatabase(PgDatabase.java:864)
        at test.Test.showFunctions(Test.java:134)
        at test.Test.main(Test.java:166)

Thanks a lot for all of you,
Takeichi.