Conversion String to UUID in Postgres and Java
In PostgresSQL's SQL grammaUsing
concat(UUID,'')
gets a text result. Using
uuid(text)
gets a UUID result.
In PostgreSQL, apart from using uuid()
, it's also possible to specify the type explicitly like ::uuid
:
with myconst (__ef_filter__id_0, __filter_workitemid_0, __filter_projectid_1, __id_2) as (values ( 'fcb8284c-1bd4-4d50-b5df-09a091b01d8c'::uuid, '9e4b70a7-c222-47dd-87cb-fbbaaf396ccd'::uuid, uuid('2b10c0a5-e35d-425d-a71a-9e473924ac4c'), uuid('3fa85f64-5717-4562-b3fc-2c963f66afa6')) )select ...
There is a class in JDK dedicated to the management of UUIDs, called java.util.UUID
. There's a static method fromString
in it that should fit your goal. As far as I can see, you can use instances of UUID in JDBC insert statements.