Re: int4 -> unix timestamp -> sql timestamp; abstime?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Roman Neuhauser <neuhauser(at)chello(dot)cz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: int4 -> unix timestamp -> sql timestamp; abstime?
Date: 2005-01-11 23:35:18
Message-ID: 5195.1105486518@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Roman Neuhauser <neuhauser(at)chello(dot)cz> writes:
> what is the opposite of cast(extract('epoch' from now()) as int)?
> The only thing I found that works is
> cast(cast(... as abstime) as timestamp)
> and the documentation says abstime shouldn't be used, and may
> disappear. What should I use instead?

The recommended locution is

SELECT TIMESTAMP WITH TIME ZONE 'epoch' + <x> * INTERVAL '1 second';

Of course you can wrap this up in a function if you prefer (not sure why
we haven't done so already).

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2005-01-12 00:12:12 Re: int4 -> unix timestamp -> sql timestamp; abstime?
Previous Message Tom Lane 2005-01-11 23:32:57 Re: Running a void function in psql