【发布时间】:2018-11-30 11:28:24
【问题描述】:
有没有办法配置 JOOQ 工具,使用 PostgresSQL 数据库的“forcedTypes”标签将 smallint 转换为 Boolean,而不提供 org.jooq.Converter 实现?
这是当前配置的样子:
<forcedTypes>
<forcedType>
<name>BOOLEAN</name>
<types>smallint.*</types>
</forcedType>
<forcedTypes>
正在使用 JOOQ v3.9.1。 PostgreSQL v9.6.6。
不幸的是,在将信息存储到数据库中时收到了下一个异常:
Caused by: org.postgresql.util.PSQLException: ERROR: column "is_complete" is of type smallint but expression is of type boolean
还尝试使用 MySQL 数据库,从 tinyint 到 Boolean 的类似转换工作正常,没有任何错误:
<forcedTypes>
<forcedType>
<name>BOOLEAN</name>
<types>tinyint.*</types>
</forcedType>
</forcedTypes>
【问题讨论】:
-
它在 MySQL 中有效,因为 MySQL 实际上没有布尔数据类型。
boolean只是那里的tinyint的别名 -
好的,那么 PostgresSQL 会出现什么问题,因为我使用的是 smallint 而不是纯布尔类型? smallint 和 tinyint 的外观非常相似
-
如果你想要一个布尔值,那么你为什么不使用
boolean -
是的,不幸的是需要使用一个现有的数据库,其中布尔值存储为小整数:)
标签: postgresql type-conversion jooq