dbTalk Databases Forums  

PG 8.3 RC1: UUID column and JDBC PreparedStatement column type

comp.databases.postgresql comp.databases.postgresql


Discuss PG 8.3 RC1: UUID column and JDBC PreparedStatement column type in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Silvio Bierman
 
Posts: n/a

Default PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-11-2008 , 09:24 AM






Hello all,

I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?

Kind regards,

Silvio Bierman

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM






Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #8  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:01 AM



Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
Quote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?
Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe


Reply With Quote
  #10  
Old   
Silvio Bierman
 
Posts: n/a

Default Re: PG 8.3 RC1: UUID column and JDBC PreparedStatement column type - 01-14-2008 , 04:34 AM



Laurenz Albe wrote:
Quote:
Silvio Bierman <sbierman (AT) jambo-software (DOT) com> wrote:
I am trying to convert an older PG database where we stored GUIDs by
explicitly converting them to byte arrays before storing them in the DB
to a database where we use the new UUID type supported by PG 8.3.

I am having trouble setting such a value through a JDBC
PreparedStatement because any stmt.setXXX(i,...) I have tried results in
an error about a mismatch between type UUID and XXX.

How can I get my PreparedStatement to work correctly?

Since there are no type casts for uuid, the only way I can see is to
use a string and explicitly cast this string (type "unknown") to uuid.

java.sql.PreparedStatement stmt =
conn.prepareStatement("UPDATE tab SET uid = ?::uuid WHERE ...");
stmt.setString(1, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11");
stmt.executeUpdate();

You would somehow have to convert your GUIDs to the format above.

Yours,
Laurenz Albe
Hello Laurens,

Thanks for the reply. I was hoping that one of the external JDBC types
could automatically be mapped/cast to GUID.

Unfortunately, changing the SQL is not an option since the application
runs on multiple database backends including Oracle, SQLServer, MySQL
and PostgreSQL. The only back-end specific twist I can do is on the
generic PreparedStatement since for each applicable type all DB code
goes througgh an adapter call like

adapter.setXXX(PreparedStatement stmt,int idx,XXX value)

which in this case actually looks like

adapter.setGUID(PreparedStatement stmt,int idx,String value)

since we represent GUID values as Strings internally.

Can I define an implicit cast in PostgreSQL?

Kind regards,

Silvio Bierman


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.