Thread: Array of UUID is not supported

Array of UUID is not supported

From
Martin Petras
Date:
Hey guys,

First of all, thanks a lot for working on the PG JDBC driver!

By using the driver version 9.2-1003-jdbc4 I'm not able to retrieve a column of type UUID[]. The error description is below.

I'm using PG 9.3, version 'PostgreSQL 9.3.0 on x86_64-apple-darwin12.5.0, compiled by Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn), 64-bit' under Mac OS 10.8.5.

Steps to reproduce:
1) run the following queries:
CREATE TABLE uuids (id UUID NOT NULL, ids UUID []);
insert into uuids values ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', '{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11,a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12}');

2) run java code:
Class.forName( "org.postgresql.Driver"); // load the driver
Connection db = DriverManager.getConnection("jdbc:postgresql://localhost:7432/test", "postgres", "postgres");
PreparedStatement ps = db.prepareStatement("select * from uuids");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
UUID id = (UUID) rs.getObject("id");
Array ids = rs.getArray("ids");
System.out.println(id + "\t" + ids + "\t" + ids.getArray()); // fails on ids.getArray()
}
rs.close();
ps.close();
db.close();

Expected: ids are a proper array of java.util.UUID objects
Current: 
Exception in thread "main" java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc4.Jdbc4Array.getArrayImpl(long,int,Map) is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:710)
at org.postgresql.jdbc2.AbstractJdbc2Array.buildArray(AbstractJdbc2Array.java:745)
at org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:171)
at org.postgresql.jdbc2.AbstractJdbc2Array.getArray(AbstractJdbc2Array.java:128)


After quick look in the code around org/postgresql/jdbc2/AbstractJdbc2Array.java:745, it seems that there are two problems:
1) type of objects in the array is resolved to java.sql.Types#OTHER
2) if it is possible to resolve the type to find out it's UUID, it's just up to call UUID.fromString( for each entry in 'input') as input already contains string representations of UUIDs

I hope you'll find some time to fix it as I'd love to use the feature in my project.

Thanks and cheers,

Martin Petras

Re: Array of UUID is not supported

From
Martin Petras
Date:
Hey guys,

There is a pull request containing the fix: https://github.com/pgjdbc/pgjdbc/pull/81

It would be great to have it review and merged to the master branch.

Cheers,

Martin Petras

From: Martin Petras <martin.petras@coresystems.ch>
Date: štvrtok, 10. októbra 2013 20:39
To: "pgsql-jdbc@postgresql.org" <pgsql-jdbc@postgresql.org>
Subject: [JDBC] Array of UUID is not supported

Hey guys,

First of all, thanks a lot for working on the PG JDBC driver!

By using the driver version 9.2-1003-jdbc4 I'm not able to retrieve a column of type UUID[]. The error description is below.

I'm using PG 9.3, version 'PostgreSQL 9.3.0 on x86_64-apple-darwin12.5.0, compiled by Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn), 64-bit' under Mac OS 10.8.5.

Steps to reproduce:
1) run the following queries:
CREATE TABLE uuids (id UUID NOT NULL, ids UUID []);
insert into uuids values ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', '{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11,a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12}');

2) run java code:
Class.forName( "org.postgresql.Driver"); // load the driver
Connection db = DriverManager.getConnection("jdbc:postgresql://localhost:7432/test", "postgres", "postgres");
PreparedStatement ps = db.prepareStatement("select * from uuids");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
UUID id = (UUID) rs.getObject("id");
Array ids = rs.getArray("ids");
System.out.println(id + "\t" + ids + "\t" + ids.getArray()); // fails on ids.getArray()
}
rs.close();
ps.close();
db.close();

Expected: ids are a proper array of java.util.UUID objects
Current: 
Exception in thread "main" java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc4.Jdbc4Array.getArrayImpl(long,int,Map) is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:710)
at org.postgresql.jdbc2.AbstractJdbc2Array.buildArray(AbstractJdbc2Array.java:745)
at org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:171)
at org.postgresql.jdbc2.AbstractJdbc2Array.getArray(AbstractJdbc2Array.java:128)


After quick look in the code around org/postgresql/jdbc2/AbstractJdbc2Array.java:745, it seems that there are two problems:
1) type of objects in the array is resolved to java.sql.Types#OTHER
2) if it is possible to resolve the type to find out it's UUID, it's just up to call UUID.fromString( for each entry in 'input') as input already contains string representations of UUIDs

I hope you'll find some time to fix it as I'd love to use the feature in my project.

Thanks and cheers,

Martin Petras

Re: Array of UUID is not supported

From
Martin Petras
Date:
Hi guys,

I noticed that the pull request https://github.com/pgjdbc/pgjdbc/pull/81 had already been merged. Thanks a lot to Minglei Tu and Dave Cramer!

Do you have any plan or idea when you might release the new version of the driver?

Thx.

Cheers,

Martin Petras

Re: Array of UUID is not supported

From
Dave Cramer
Date:
Martin,

Snapshots are on maven, I am hoping to get a new driver released today actually.

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Fri, Nov 1, 2013 at 5:14 AM, Martin Petras <Martin.Petras@coresystems.ch> wrote:
Hi guys,

I noticed that the pull request https://github.com/pgjdbc/pgjdbc/pull/81 had already been merged. Thanks a lot to Minglei Tu and Dave Cramer!

Do you have any plan or idea when you might release the new version of the driver?

Thx.

Cheers,

Martin Petras


Re: Array of UUID is not supported

From
Martin Petras
Date:
Perfect! Thanks!