PostgreSQL undocumented timenow() function?
-
14-03-2021 - |
Question
Looking at the documentation of PostgreSQL I couldn't find anything on timenow()
. Yet if I call the function it works.
So what is the difference between now()
and timenow()
?
I am going to guess that now()
is based on transaction while timenow()
is server OS time or am I completely off?
The below is DataGrip's auto generated definition. All system functions (for example sum
) all have missing source code
and as you can see it's part of the pg_catalog
schema.
La solution
Yes, this is undocumented, very old, deprecated for a long time ago stuff.
The key difference from the NOW
function is the data type of the result. timenow
used the type abstime
, which was less accurate and prone to the year 2038 problem. There is a small note in the documentation:
The types abstime and reltime are lower precision types which are used internally. You are discouraged from using these types in applications; these internal types might disappear in a future release.
This type was completely removed in postgresql 12 with all related functions. Per source code I can confirm: yes, timenow
will return real time by every call, not the time of transaction start.
You could achieve same result by using clock_timestamp()
function instead of now()