[英]Insert Interval data using jooq
I have a PostgreSQL table with column with column name test_interval and type interval.我有一个 PostgreSQL 表,其列名为 test_interval,类型为 interval。
test_interval interval
I am using jooq to insert the data in the table.我正在使用 jooq 在表中插入数据。 In my TestTable.java class, the field is of type:
在我的 TestTable.java class 中,该字段的类型为:
public final TableField<TestTable, YearToSecond> TEST_INTERVAL = createField(DSL.name("test_interval"), org.jooq.impl.SQLDataType.INTERVAL.nullable(false), this, "");
I am creating the table as:我将表格创建为:
dsl.createTableIfNotExists(TestTable)
.column(TestTable.TEST_INTERVAL)
.execute()
I want to insert the data into the table and the data is of form:我想将数据插入表中,数据的形式为:
val str = "0 years 0 mons 0 days 0 hours 15 mins 0.00 secs"
dsl.insertInto(
TestTable,
TestTable.TEST_INTERVAL
).values(
str
)
I get error can not insert of type.我得到错误无法插入类型。 How can i insert data of the interval data type of postgres using jooq?
如何使用 jooq 插入 postgres 的区间数据类型的数据?
Your TEST_INTERVAL
column is of type YearToSecond
, so you have to insert a value of that type, not of type String
.您的
TEST_INTERVAL
列属于YearToSecond
类型,因此您必须插入该类型的值,而不是String
类型的值。
Just call the YearToSecond
constructor只需调用
YearToSecond
构造函数
new YearToSecond(
new YearToMonth(),
new DayToSecond(0, 0, 15)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.