I am trying to get the elapsed time for transaction. I need to extract it then to a file.
I found some SQL online for Derby that does not work as I would like it:
ij> create table atab1(ts timestamp, i int, ts1 timestamp);
ij> insert into atab1 values(CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP);
1 row inserted/updated/deleted
ij> insert into atab1 values(CURRENT_TIMESTAMP, 2, CURRENT_TIMESTAMP);
1 row inserted/updated/deleted
ij> select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, ts1,ts)} as TS_DIFF from atab1;
TS_DIFF
-----------
0
0
The content of the atab1 table is :
TS |I |TS1
-----------------------------------------------------------------------
2012-08-05 00:20:16.675 |1 |2012-08-05 00:20:16.675
2012-08-05 00:20:29.081 |2 |2012-08-05 00:20:29.081
The statement:
select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, ts1,ts)} as TS_DIFF from atab1;
will always give 0 as the values for ts1 and ts are the same
How should I adjust the statement so it would show the difference between the values of ts and ts1?
It seems like you should have two different rows: one is the start row, and one is the end row. Each row should have a transaction id, and a timestamp, and one should have a code that indicates it is the start row, while the other should have a code that indicates it is the end row.
Then, you can select those two rows by self-joining the table on its transaction id, and then you can subtract the start time from the end time to get the elapsed time.