PostgreSQL statement_timestamp() Function

The PostgreSQL statement_timestamp() function returns the timestamp for the starting execution of the current statement.

statement_timestamp() Syntax

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

statement_timestamp() -> timestamp

Parameters

The PostgreSQL statement_timestamp() function does not require any parameters.

Return value

The PostgreSQL statement_timestamp() function returns the current system date and time with time zone information, which is start time of the current statement.

That is, all statement_timestamp() functions in a statement return the same value, it is different from clock_timestamp().

statement_timestamp() Examples

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

SELECT statement_timestamp();
     statement_timestamp
-------------------------------
 2022-05-15 22:17:34.819513+03

The statement_timestamp() function returns the date and time when the statement executed, not the date and time when this function was executed. See the example below:

SELECT
    statement_timestamp(),
    pg_sleep(1),
    statement_timestamp();
-[ RECORD 1 ]---------------------------
statement_timestamp      | 2022-05-15 22:18:31.076406+03
pg_sleep |
statement_timestamp      | 2022-05-15 22:18:31.076406+03

Here, even though we use pg_sleep(1) in the middle of the two statement_timestamp() functions to pause execution for 1 second, the values returned by both statement_timestamp() functions is still the same.