Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
CURRENT_GLOBAL_TIMESTAMP()
CURRENT_GLOBAL_TIMESTAMP function returns the global transaction timestamp of the database server. In a distributed database environment, this function ensures all nodes return a unified timestamp value, avoiding timestamp inconsistencies caused by unsynchronized node times.NOW() function lies in:NOW() function returns the local time of the current connection, namely the machine time of the SQL node.CURRENT_GLOBAL_TIMESTAMP() returns the global transaction timestamp, which is the GTS hybrid logical clock for cluster timing. Shifting the hybrid logical clock right by 24 bits (>>24) yields the Unix timestamp, which can then be used to derive the physical time corresponding to GTS.tdsql> SELECT CURRENT_GLOBAL_TIMESTAMP();+----------------------------+| CURRENT_GLOBAL_TIMESTAMP() |+----------------------------+| 29647834336722979 |+----------------------------+1 row in set (0.01 sec)
INSERT INTO transaction_log (id, amount, create_time)VALUES (1001, 500.00, CURRENT_GLOBAL_TIMESTAMP());
tdsql> SELECT FROM_UNIXTIME(CURRENT_GLOBAL_TIMESTAMP() >> 24) AS formatted_time;+---------------------+| formatted_time |+---------------------+| 2025-12-31 10:37:42 |+---------------------+1 row in set (0.00 sec)
피드백