current_timestamp

A function returning the point-in-time the current transaction started

current_timestamp is a system function returning a timestamp representing the point-in-time at which the current transaction started.

current_timestamp was added in PostgreSQL 6.2.

Usage

current_timestamp → timestamp with time zone

Despite its name, current_timestamp returns the point-in-time when the current transaction was started, not the actual time the function was executed (for this see clock_timestamp()). The function transaction_timestamp() was added in PostgreSQL 8.2 to provide an unambiguous function for retrieving the current transaction's start time.

A variant of this function, current_timestamp(), is provided for retrieving the transaction timestamp with the specified precision:

current_timestamp ( integer ) → timestamp with time zone

Note that current_timestamp cannot be invoked as current_timestamp().

Change history

Examples

Basic execution example for current_timestamp:

postgres=# SELECT current_timestamp;
       current_timestamp       
-------------------------------
 2021-06-17 19:25:22.955989+01
(1 row)

current_timestamp will always report the same value as transaction_timestamp(), and (if executed in an implicit transaction) the same value as statement_timestamp():

postgres=# SELECT
              current_timestamp,
              transaction_timestamp(),
              statement_timestamp(),
              clock_timestamp()\gx
-[ RECORD 1 ]---------+------------------------------
current_timestamp     | 2021-06-17 19:26:40.599694+01
transaction_timestamp | 2021-06-17 19:26:40.599694+01
statement_timestamp   | 2021-06-17 19:26:40.599694+01
clock_timestamp       | 2021-06-17 19:26:40.600033+01

The precision (number of subsecond digits) can be optionally specified:

postgres=# SELECT current_timestamp(3);
     current_timestamp      
----------------------------
 2021-06-17 20:07:24.741+01
(1 row)

The specified precision must be between 0 and 6; larger values will be reduced to 6:

postgres=# SELECT current_timestamp(99);
WARNING:  TIMESTAMP(99) WITH TIME ZONE precision reduced to maximum allowed, 6
       current_timestamp       
-------------------------------
 2021-06-17 20:08:32.147416+01
(1 row)

The variant current_timestamp() is not valid:

postgres=# SELECT current_timestamp();
ERROR:  syntax error at or near ")"
LINE 1: SELECT current_timestamp();

Categories

Date and time, System function

See also

current_time, current_date, transaction_timestamp(), clock_timestamp()