使用jooq插入间隔数据

问题描述 投票:0回答:1

我有一个PostgreSQL表,表的列名是test_interval,类型是interval。

test_interval interval

我使用jooq来插入表中的数据。在我的TestTable.java类中,字段的类型是:"测试"。

public final TableField<TestTable, YearToSecond> TEST_INTERVAL = createField(DSL.name("test_interval"), org.jooq.impl.SQLDataType.INTERVAL.nullable(false), this, "");

我创建的表是:

dsl.createTableIfNotExists(TestTable)
   .column(TestTable.TEST_INTERVAL)
   .execute()  

我想把数据插入到表中,数据是表格。

val str = "0 years 0 mons 0 days 0 hours 15 mins 0.00 secs"   
dsl.insertInto(
    TestTable,
    TestTable.TEST_INTERVAL
).values(
    str
)

我得到错误不能插入的类型。如何使用jooq插入Postgres的区间数据类型的数据?

java postgresql jooq querydsl jooq-sbt-plugin
1个回答
0
投票

你的 TEST_INTERVAL 列为 YearToSecond所以你必须插入一个该类型的值,而不是类型为 String.

呼叫 YearToSecond 构造者

new YearToSecond(
  new YearToMonth(),
  new DayToSecond(0, 0, 15)
)
© www.soinside.com 2019 - 2024. All rights reserved.