SQL query object to Postgres UUID

1,007 views
Skip to first unread message

Dan Capri

unread,
Aug 26, 2013, 5:38:17 PM8/26/13
to jd...@googlegroups.com

Hello

Does anyone have a solution for mapping either a Java UUID or a string to a postgres UUID column using JDBI SQL Query Objects?

I have a requirement to use Postgres UUIDs for storing UUIDs. In my application, I am converting Java UUIDs into Strings using a factory.   However, when using JDBI SQL Query Objects, Im unable to map the strings to Postgres UUIDs.  Ive scoured google and other than the stack overflow article explaing how to convert Java UUIDs to strings, I have not been able to find anything on the subject.   

Here is the error I receive when attempting mapping strings to Postgres UUID.  Im not opposed to switching over to JDBI Handles  but id have to refactor a fair amount of code.

ERROR [2013-08-26 20:05:19,428] com.yammer.dropwizard.jersey.LoggingExceptionMapper: Error handling a request: 2743749f0c7355a1
! org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: column "account_id" is of type uuid but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.

Thank you in advance.  


Steven Schlansker

unread,
Aug 27, 2013, 1:05:31 PM8/27/13
to jd...@googlegroups.com
If you are using a relatively recent PgJDBC driver, you should be able to just use the UUID as an argument to PreparedStatement.setObject, which should mean that if you use the UUID object directly through JDBI it should all "just work"

Worst case, you could register an ArgumentFactory to do this.

You shouldn't need to convert the UUID to a string.

Hope that helps,
Steven
> --
> You received this message because you are subscribed to the Google Groups "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages