PostgreSQL TRANSACTION_TIMESTAMP() Function
The PostgreSQL TRANSACTION_TIMESTAMP() function returns the current date and time with the time zone. This function returns the current date as a 'YYYY-MM-DD HH:MM:SS.US+TZ' format.
Syntax
TRANSACTION_TIMESTAMP()
Parameters
No parameter is required.
Return Value
Returns the current date as a 'YYYY-MM-DD HH:MM:SS.US+TZ' format.
Example 1:
The example below shows the usage of TRANSACTION_TIMESTAMP() function.
SELECT TRANSACTION_TIMESTAMP(); Result: '2021-12-27 08:01:29.125744+00'
Example 2:
Consider a database table called EmployeeLogin with the following records:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | 2019-10-25 09:20:38.125744+00 |
2 | Marry | 2019-10-25 09:21:05.426844+00 |
3 | Jo | 2019-10-25 09:24:35.378744+00 |
4 | Kim | 2019-10-25 09:25:24.221133+00 |
5 | Ramesh | 2019-10-25 09:27:16.274011+00 |
To insert a new record in this table, the following statement can be used.
INSERT INTO EmployeeLogin VALUES (6, 'Suresh', TRANSACTION_TIMESTAMP()); -- see the result SELECT * FROM EmployeeLogin;
This will produce a result similar to:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | 2019-10-25 09:20:38.125744+00 |
2 | Marry | 2019-10-25 09:21:05.426844+00 |
3 | Jo | 2019-10-25 09:24:35.378744+00 |
4 | Kim | 2019-10-25 09:25:24.221133+00 |
5 | Ramesh | 2019-10-25 09:27:16.274011+00 |
6 | Suresh | 2019-10-25 09:28:19.014011+00 |
❮ PostgreSQL Functions