当试图使用JDBI更新或插入包含PostgreSQL中的间隔的表时,我得到以下错误:org.jdbi.v3.core.statement.UnableToCreateStatementException: No argument factory registered for '1 years 0 mons 0 days 0 hours 0 mins 0.0 secs' of qualified type org.postgresql.util.PGInterval [...]
最小可重现性示例:
CREATE TABLE testing (i INTERVAL);Jdbi.create(PGSimpleDataSource().apply {
setURL([connection string goes here])
}).withHandle<Int, SQLException> { handle: Handle ->
handle.createUpdate("INSERT INTO testing(i) VALUES (:interval)")
.bind("interval", PGInterval(1, 0, 0, 0, 0, 0.0))
.execute()
}由于查询接受'P1Y',我尝试将其作为字符串插入,但这给了我ERROR: column "i" is of type interval but expression is of type character varying,如果第一个方法有效,这将是有意义的。
似乎只有PGIntervals作为预期的类型才有意义,因为当从结果集获得间隔时,会返回一个PGInterval。
虽然我怀疑这会有什么关系,但我用的是:
发布于 2021-06-07 06:52:09
我认为您应该使用PostgreSQL JDBI插件来处理PostgreSQL特定类型。
https://stackoverflow.com/questions/67864747
复制相似问题