tencent cloud

TDSQL Boundless

CURRENT_GLOBAL_TIMESTAMP

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-03-06 18:48:07

Declaration

CURRENT_GLOBAL_TIMESTAMP()

Description

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.
The main difference between this function and the NOW() function lies in:
The 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.

Examples

Basic Usage
tdsql> SELECT CURRENT_GLOBAL_TIMESTAMP();
+----------------------------+
| CURRENT_GLOBAL_TIMESTAMP() |
+----------------------------+
| 29647834336722979 |
+----------------------------+
1 row in set (0.01 sec)
Usage in Data Insertion
INSERT INTO transaction_log (id, amount, create_time)
VALUES (1001, 500.00, CURRENT_GLOBAL_TIMESTAMP());
Formatted Output
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)


Ajuda e Suporte

Esta página foi útil?

comentários