Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a real time within PostgreSQL transaction?

As far as I understand now() returns the same time during the whole PostgreSQL transaction? But how to get real time?

Also, I am interested if there any configuration parameter to limit duration of transaction, so that after this period expiration transaction would immediately fail or somehow else prohibit following queries?

like image 895
seas Avatar asked Jul 29 '10 14:07

seas


People also ask

How do I get the current time in PostgreSQL?

Postgresql now() The NOW() function in Postgresql is used to get the current date and time. The return type of the NOW() function is the timestamp with the time zone. We can fetch the current date and time by using the PostgreSQL NOW() function. This function has a return type i.e. the timestamp with the time zone.

What is now () in PostgreSQL?

What is PostgreSQL Now Function? The Now() function is used to return the current date and time of the time zone (default or user-defined). Its return type is the timestamp with the time zone.

How do I select a timestamp in PostgreSQL?

select 'date: time' :: timestamp; select CURRENT_TIMESTAMP :: timestamp; Below is the parameter description of the above syntax are as follows: Select: Select is used to select timestamp value in timestamp syntax.

Does PostgreSQL have a transaction log?

In PostgreSQL, it is also known as a transaction log. A log is a record of all the events or changes and WAL data is just a description of changes made to the actual data. So, it is 'data about data' or metadata.


2 Answers

Use clock_timestamp().

now() is a traditional PostgreSQL equivalent to transaction_timestamp(), which is equivalent to CURRENT_TIMESTAMP. These functions return the start time of the current transaction. Their values do not change during the transaction.

statement_timestamp() returns the time of receipt of the latest command message from the client.

clock_timestamp() returns the actual current time, and therefore its value changes even within a single SQL command.

For more information see the documentation.

like image 176
Fernando Correia Avatar answered Sep 22 '22 13:09

Fernando Correia


Timeofday() 

May work for you.

like image 41
Tobiasopdenbrouw Avatar answered Sep 22 '22 13:09

Tobiasopdenbrouw