用于 postgres 的最新 Java JDBC 驱动程序声称原生支持 UUID;针对 Postgres 9.2 (mac) 工作。
实际上,当使用 PreparedStatement 时,我可以单步执行驱动程序代码,甚至可以遍历 AbstractJdbc3gStatement.java 中专门的“setUuid”函数。种种迹象表明,它应该“正常工作”。
但是,它不起作用。数据库抛出一个错误,我因此收到:
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 139
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) ~[postgresql-9.2-1002.jdbc4.jar:na]
是的,确实,JDBC 驱动程序中的 setUuid 确实将其作为 bytea 发送:
private void setUuid(int parameterIndex, UUID uuid) throws SQLException {
if (connection.binaryTransferSend(Oid.UUID)) {
byte[] val = new byte[16];
ByteConverter.int8(val, 0, uuid.getMostSignificantBits());
ByteConverter.int8(val, 8, uuid.getLeastSignificantBits());
bindBytes(parameterIndex, val, Oid.UUID);
} else {
bindLiteral(parameterIndex, uuid.toString(), Oid.UUID);
}
}
是什么赋予了?实际数据库中是否需要一些魔法符文来祝福这种转换?