I am trying to run a query of the following form with jooq in Kotlin:
val create = DSL.using(SQLDialect.POSTGRES)
val query: Query = create.select().from(DSL.table(tableName))
.where(DSL.field("timestamp").between("1970-01-01T00:00:00Z").and("2021-11-05T00:00:00Z"))
.orderBy(DSL.field("id").desc())
The code above gives me:
syntax error at or near \"and\
Also, looking at this query in the debugger, the query.sql renders as:
select * from data_table where timestamp between ? and ? order by id desc
I am not sure if the ? indicates that it could not render the values to SQL or somehow they are some sort of placeholders..
Also, the code works without the where chain.
Additionally, on the Postgres command line I can run the following and the query executes:
select * from data_table where timestamp between '1970-01-01T00:00:00Z' and '2021-11-05T00:00:00Z' order by id
Querying the datatypes on the schema, the timestamp column type is rendered as timestamp without time zone.
Before I had declared variables as:
val lowFilter = "1970-01-01T00:00:00Z"
val highFilter = "2021-11-05T00:00:00Z"
and this did not work and it seems passing raw strings does not work either. I am very new to this, so I am pretty sure I am messing up the usage here.
EDIT Following @nulldroid suggestion, did something like:
.where(DSL.field("starttime").between(DSL.timestamp("1970-01-01T00:00:00Z")).and(DSL.timestamp("2021-11-05T00:00:00Z")))
and this resulted in:
Type class org.jooq.impl.Val is not supported in dialect POSTGRES"