localtimestamp

A function returning the timestamp when the current transaction started

localtimestamp is a is a system function returning the timestamp at which the current transaction started, without the time zone.

localtimestamp was added in PostgreSQL 7.3.

Usage

localtimestamp → timestamp
localtimestamp ( integer ) → timestamp

The optional integer parameter determines to how many digits the fractional digits in the seconds field should be rounded.

For an equivalent function returning a timestamp with time zone, see current_timestamp.

Change history

Examples

Basic usage example for localtimestamp:

postgres=# SELECT localtimestamp;
       localtimestamp       
----------------------------
 2022-12-30 11:13:39.167389
(1 row)

Speciftying the precision:

postgres=# SELECT localtimestamp(0);
   localtimestamp    
---------------------
 2022-12-30 11:14:38
(1 row)

postgres=# SELECT localtimestamp(3);
     localtimestamp      
-------------------------
 2022-12-30 11:14:40.631
(1 row)

A precision greater than 6 will be rounded down:

postgres=# SELECT localtimestamp(7);
WARNING:  TIMESTAMP(7) precision reduced to maximum allowed, 6
       localtimestamp       
----------------------------
 2022-12-30 11:15:47.828753
(1 row)

Categories

Date and time, System function

See also

localtime, current_timestamp