PostgreSQL clock_timestamp() Function

The PostgreSQL clock_timestamp() function returns the date and time when this function was executed. Two executions of clock_timestamp() may return different values.

clock_timestamp() Syntax

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

clock_timestamp() -> TIMESTAMP WITH TIME ZONE

Parameters

The PostgreSQL clock_timestamp() function does not have any parameters.

Return value

The PostgreSQL clock_timestamp() function returns a date and time with time zone information, which is the system date and time when this function was executed.

Note that the clock_timestamp() function is different from current_timestamp(), transaction_timestamp() and now(). current_timestamp(), transaction_timestamp() and now() return the time when the transaction, function, or stored procedure started executing.

clock_timestamp() Examples

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

SELECT clock_timestamp();
        clock_timestamp
-------------------------------
 2022-05-14 15:31:41.835509+03

During statement execution, the two clock_timestamp() functions return different values, as in the following example:

SELECT
    clock_timestamp(),
    pg_sleep(1),
    clock_timestamp();
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2022-05-14 15:37:40.019238+03
pg_sleep        |
clock_timestamp | 2022-05-14 15:37:41.020112+03

Here we can see that the first clock_timestamp() is later than the second clock_timestamp() for one second, because the pg_sleep(1) function pauses the execution for 1 second.