current_time

A function returning the time the current transaction started

current_time is a system function returning the time at which the current transaction started.

current_time was added in PostgreSQL 6.2.

Usage

current_time → time with time zone

Despite its name, current_time returns the time when the current transaction was started, not the actual time the function was executed (this can be retrieved via clock_timestamp()).

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

current_time ( integer ) → timestamp with time zone

Note that current_time cannot be invoked as current_time().

Change history

Examples

Basic execution example for current_time:

postgres=# SELECT current_time;
    current_time    
--------------------
 20:22:38.562496+01
(1 row)

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

postgres=# SELECT
              current_time,
              transaction_timestamp(),
              statement_timestamp(),
              clock_timestamp()\gx
-[ RECORD 1 ]---------+------------------------------
current_time          | 20:26:13.979644+01
transaction_timestamp | 2021-06-17 20:26:13.979644+01
statement_timestamp   | 2021-06-17 20:26:13.979644+01
clock_timestamp       | 2021-06-17 20:26:13.980394+01

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

postgres=# SELECT current_time(3);
  current_time   
-----------------
 20:30:13.684+01
(1 row)

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

postgres=# SELECT current_time(99);
WARNING:  TIME(99) WITH TIME ZONE precision reduced to maximum allowed, 6
    current_time    
--------------------
 20:31:02.153981+01
(1 row)

The variant current_time() is not valid:

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

Categories

Date and time, System function

See also

current_timestamp, current_date, transaction_timestamp(), clock_timestamp()