KingbaseES 时间函数有两大类:返回事务开始时间和返回语句执行时的时间。具体函数看以下例子:
test=# select now(),sys_sleep(1),now(); now | sys_sleep | now -------------------------------+-----------+------------------------------- 2021-09-13 17:00:20.608055+08 | | 2021-09-13 17:00:20.608055+08 (1 row) test=# select current_time ,sys_sleep(1),current_time; current_time | sys_sleep | current_time --------------------+-----------+-------------------- 17:00:21.613050+08 | | 17:00:21.613050+08 (1 row) test=# select transaction_timestamp(),sys_sleep(1),transaction_timestamp(); transaction_timestamp | sys_sleep | transaction_timestamp -------------------------------+-----------+------------------------------- 2021-09-13 17:00:22.626277+08 | | 2021-09-13 17:00:22.626277+08 (1 row) test=# select clock_timestamp(),sys_sleep(1),clock_timestamp(); clock_timestamp | sys_sleep | clock_timestamp -------------------------------+-----------+------------------------------- 2021-09-13 17:00:24.644381+08 | | 2021-09-13 17:00:25.645639+08 (1 row) test=# select timeofday(),sys_sleep(1),timeofday(); timeofday | sys_sleep | timeofday -------------------------------------+-----------+------------------------------------- Mon Sep 13 17:00:25.647681 2021 CST | | Mon Sep 13 17:00:26.650114 2021 CST (1 row)
clock_timestamp ,timeofday 返回的是函数 执行时刻的时间;而 now, current_time , transaction_timestamp 返回的都是事务开始的时间。
statement_timestamp 比较特殊:
test=# select statement_timestamp(),sys_sleep(1),statement_timestamp(); statement_timestamp | sys_sleep | statement_timestamp -------------------------------+-----------+------------------------------- 2021-09-13 17:00:23.635612+08 | | 2021-09-13 17:00:23.635612+08 (1 row) test=# begin; BEGIN test=# select statement_timestamp(); statement_timestamp ------------------------------- 2021-09-13 17:04:14.442012+08 (1 row) test=# select statement_timestamp(); statement_timestamp ------------------------------- 2021-09-13 17:04:20.638240+08 (1 row) test=# commit;