1

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.

enter image description here

7
  • didn't see any timenow function in my database. Are you sure this is not your custom (user-defined) function? – Melkij Jan 20 at 11:44
  • edited the question to add auto generated definition and more details. It's not a user defined function. Is it possible it's part of some sort of extension? – Chessbrain Jan 20 at 11:48
  • Yep, returns abstime helps a lot. (writing answer) – Melkij Jan 20 at 12:06
  • 1
    Also: the type abstime was removed in Postgres 12 (it has been declared as obsolete for quite a while) – a_horse_with_no_name Jan 20 at 12:18
  • 2
    Actually it was a "native" function. Try dbfiddle.uk/… – Melkij Jan 20 at 12:26
3

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.