Re: int4 -> unix timestamp -> sql timestamp; abstime? - Mailing list pgsql-general

From Tom Lane
Subject Re: int4 -> unix timestamp -> sql timestamp; abstime?
Date
Msg-id 5195.1105486518@sss.pgh.pa.us
Whole thread Raw
In response to int4 -> unix timestamp -> sql timestamp; abstime?  (Roman Neuhauser <neuhauser@chello.cz>)
Responses Re: int4 -> unix timestamp -> sql timestamp; abstime?  (Michael Glaesemann <grzm@myrealbox.com>)
Re: int4 -> unix timestamp -> sql timestamp; abstime?  (Roman Neuhauser <neuhauser@chello.cz>)
Re: int4 -> unix timestamp -> sql timestamp; abstime?  (David Fetter <david@fetter.org>)
List pgsql-general
Roman Neuhauser <neuhauser@chello.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Running a void function in psql
Next
From: Michael Glaesemann
Date:
Subject: Re: int4 -> unix timestamp -> sql timestamp; abstime?