KingbaseES提供了多种的时间函数,这些函数在使用过程中存在哪些不同?
**同一事务**
test=# begin
test-# for i in 1.. 10 loop
test-# raise notice 'time1:%,time2:%,time3:%,time4:%,time5:%' ,localtimestamp,current_timestamp,now,clock_timestamp,sysdate;
test-# select sys_sleep(1);
test-# end loop;
test-# end;
test-# /
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:44.191915+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:45.195306+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:46.198489+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:47.200910+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:48.203675+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:49.206851+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:50.209895+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:51.213113+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:52.215484+08,time5:2022-08-18 17:55:44
注意: time1:2022-08-18 17:55:44.191142,time2:2022-08-18 17:55:44.191142+08,time3:2022-08-18 17:55:44.191142+08,time4:2022-08-18 17:55:53.217494+08,time5:2022-08-18 17:55:44
ANONYMOUS BLOCK
**不同事务**
test=# begin
test-# for i in 1.. 10 loop
test-# raise notice 'time1:%,time2:%,time3:%,time4:%,time5:%' ,localtimestamp,current_timestamp,now,clock_timestamp,sysdate;
test-# select sys_sleep(1);
test-# commit;
test-# end loop;
test-# end;
test-# /
注意: time1:2022-08-18 18:07:57.167887,time2:2022-08-18 18:07:57.167887+08,time3:2022-08-18 18:07:57.167887+08,time4:2022-08-18 18:07:57.168379+08,time5:2022-08-18 18:07:57
注意: time1:2022-08-18 18:07:58.171508,time2:2022-08-18 18:07:58.171508+08,time3:2022-08-18 18:07:58.171508+08,time4:2022-08-18 18:07:58.171549+08,time5:2022-08-18 18:07:58
注意: time1:2022-08-18 18:07:59.174077,time2:2022-08-18 18:07:59.174077+08,time3:2022-08-18 18:07:59.174077+08,time4:2022-08-18 18:07:59.174110+08,time5:2022-08-18 18:07:59
注意: time1:2022-08-18 18:08:00.177034,time2:2022-08-18 18:08:00.177034+08,time3:2022-08-18 18:08:00.177034+08,time4:2022-08-18 18:08:00.177083+08,time5:2022-08-18 18:08:00
注意: time1:2022-08-18 18:08:01.179995,time2:2022-08-18 18:08:01.179995+08,time3:2022-08-18 18:08:01.179995+08,time4:2022-08-18 18:08:01.180137+08,time5:2022-08-18 18:08:01
注意: time1:2022-08-18 18:08:02.183390,time2:2022-08-18 18:08:02.183390+08,time3:2022-08-18 18:08:02.183390+08,time4:2022-08-18 18:08:02.183421+08,time5:2022-08-18 18:08:02
注意: time1:2022-08-18 18:08:03.185189,time2:2022-08-18 18:08:03.185189+08,time3:2022-08-18 18:08:03.185189+08,time4:2022-08-18 18:08:03.185221+08,time5:2022-08-18 18:08:03
注意: time1:2022-08-18 18:08:04.185869,time2:2022-08-18 18:08:04.185869+08,time3:2022-08-18 18:08:04.185869+08,time4:2022-08-18 18:08:04.185916+08,time5:2022-08-18 18:08:04
注意: time1:2022-08-18 18:08:06.152150,time2:2022-08-18 18:08:06.152150+08,time3:2022-08-18 18:08:06.152150+08,time4:2022-08-18 18:08:06.152392+08,time5:2022-08-18 18:08:06
注意: time1:2022-08-18 18:08:07.153191,time2:2022-08-18 18:08:07.153191+08,time3:2022-08-18 18:08:07.153191+08,time4:2022-08-18 18:08:07.153222+08,time5:2022-08-18 18:08:07
ANONYMOUS BLOCK
可以看出在同一事务中只有clock_timestamp显示的是实时时间,其他函数记录的都是事务开始时间。而在不同的事务中,所有函数都是显示实时时间。
KingbaseES认为返回事务开始时间点的时间有利于保证同一事务的多个修改保持同样的时间戳。这点与oracle机制不同,oracle默认返回实时时间。