首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JDBI无法将PGInterval绑定到PostgreSQL间隔

JDBI无法将PGInterval绑定到PostgreSQL间隔
EN

Stack Overflow用户
提问于 2021-06-07 00:33:29
回答 1查看 194关注 0票数 0

当试图使用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 [...]

最小可重现性示例:

  • 在数据库中:
代码语言:javascript
复制
CREATE TABLE testing (i INTERVAL);
  • 在Kotlin中(在普通Java中可能产生相同的结果):
代码语言:javascript
复制
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。

虽然我怀疑这会有什么关系,但我用的是:

  • PostgreSQL 13.2 (Debian 13.2-1.pgdg 100+1)在x86_64-pc-linux-gnu上,由gcc (Debian 8.3.0-6) 8.3.0,64位编译
  • org.jdbi:jdbi3-core:3.18.1 + org.jdbi:jdbi3-kotlin:3.18.1 + org.postgresql:postgresql:42.2.19
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-07 06:52:09

我认为您应该使用PostgreSQL JDBI插件来处理PostgreSQL特定类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67864747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档