PostgreSQL current_timestamp() Function

The PostgreSQL current_timestamp() function returns the current date and time (start of current transaction).

current_timestamp() Syntax

Here is the syntax of the PostgreSQL current_timestamp() function:

current_timestamp -> TIMESTAMP WITH TIME ZONE

or

current_timestamp(precision) -> TIMESTAMP WITH TIME ZONE

Parameters

precision

Required. It is an integer indicating the precision of fractional seconds.

Return value

The PostgreSQL current_timestamp() function returns a date and time with time zone information, that is the system date and time of starting of the current transaction.

That is, all current_timestamp() functions in a transaction return the same value, which is different from clock_timestamp().

current_timestamp() Examples

This example shows how to use the PostgreSQL current_timestamp() function to get the current date and time.

SELECT current_timestamp;
       current_timestamp
-------------------------------
 2022-05-14 15:55:37.222601+03

Or use the following statement to limit the precision of fractional seconds:

SELECT
    current_timestamp(0),
    current_timestamp(1),
    current_timestamp(2),
    current_timestamp(3),
    current_timestamp(4),
    current_timestamp(5),
    current_timestamp(6);
current_timestamp | 2022-05-14 15:57:26+03
current_timestamp | 2022-05-14 15:57:25.5+03
current_timestamp | 2022-05-14 15:57:25.52+03
current_timestamp | 2022-05-14 15:57:25.518+03
current_timestamp | 2022-05-14 15:57:25.5176+03
current_timestamp | 2022-05-14 15:57:25.51761+03
current_timestamp | 2022-05-14 15:57:25.517606+03

The current_timestamp() function returns the time of starting of the current transaction, not the time when the function was executed. See the example below:

SELECT
    current_timestamp,
    pg_sleep(1),
    current_timestamp;
-[ RECORD 1 ]-----+------------------------------
current_timestamp | 2022-05-14 15:59:08.628751+03
pg_sleep          |
current_timestamp | 2022-05-14 15:59:08.628751+03

Here, even though we used pg_sleep(1) in both current_timestamp functions to pause execution for 1 second, the time returned by both current_timestamp functions are still the same.