I have a PostgreSQL table with column with column name test_interval and type interval.
test_interval interval
I am using jooq to insert the data in the table. In my TestTable.java class, the field is of type:
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?
Your
TEST_INTERVAL
column is of typeYearToSecond
, so you have to insert a value of that type, not of typeString
.Just call the
YearToSecond
constructor