Result<Record2<BigInteger, DayToSecond>> record = create
.select(
TEST.ID, timestampDiff(TEST.ARRIVAL, lag(TEST.DEPARTURE).over().orderBy(TEST.ID)).as("time_diff")
).from(TEST)
.orderBy(TEST.ID)
.fetch();Hi,
I am testing the query above. But I found 2 difficulties:
1.) timestampDiff only takes TIMESTAMP columns as parameters. But mostly we are working with Oracle's DATE types. These are not working here. Would it be possible to overload the timestampDiff method for the DATE types?
2.) I am using an alias to rename the new calculated column - because it is has a new semantic meaning and a new data type. But now jOOQ is losing the type safety. On fetching I have to do an explicit type cast to DayToSecond if I want to fetch the "time_diff" column:
for (int i = 0; i < record.size(); i++) {
Record2<BigInteger, DayToSecond> entry = record.get(i);
DayToSecond timeDiff = (DayToSecond)entry.get("time_diff");
System.out.println(entry.get(TEST.ID) + ": " + (timeDiff != null ? timeDiff.getTotalMinutes() : null));
}Is there a better way?
Greets, Mark
CREATE TABLE schema.test
(id integer, arrival timestamp, departure timestamp)
;
INSERT INTO schema.test
(id, arrival, departure)
VALUES
(0, NULL, '2000-01-01 22:00:00.000'),
(1, '2000-01-01 22:30:00.000', '2000-01-01 22:35:00.000'),
(2, '2000-01-01 23:10:00.000', '2000-01-01 23:10:00.000'),
(3, '2000-01-01 23:50:00.000', '2000-01-01 23:55:00.000'),
(4, '2000-01-02 00:10:00.000', '2000-01-02 00:10:00.000'),
(5, '2000-01-02 01:30:00.000', NULL)
;Field<DayToSecond> timeDiff = timestampDiff(TEST.ARRIVAL, lag(TEST.DEPARTURE).over().orderBy(TEST.ID)).as("time_diff");
Result<Record2<BigInteger, DayToSecond>> record = create
for (int i = 0; i < record.size(); i++) {Record2<BigInteger, DayToSecond> entry = record.get(i);
DayToSecond d = entry.get(timeDiff);System.out.println(entry.get(TEST.ID) + ": " + (d != null ? d.getTotalMinutes() : null));}