By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,691 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,691 IT Pros & Developers. It's quick & easy.

How to convert a UnixTimestamp to a PostgreSQL date without using ::abstime ?

P: n/a
Hello,

I'm looking for a way to convert a unix timestamp to a PostgreSQL date
without using ::abstime which seems to be deprecated.

Currently, I do that query :

levure=> select 1063147331.843::int4::abstime;
abstime
------------------------
2003-09-10 00:42:12+02
(1 row)
What can I use to replace the abstime type in ?

Thanks in advance :-)

---------------------------------------
Bruno BAGUETTE - pg******@baguette.net
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, Sep 10, 2003 at 01:47:20 +0200,
Bruno BAGUETTE <pg******@baguette.net> wrote:

I'm looking for a way to convert a unix timestamp to a PostgreSQL date
without using ::abstime which seems to be deprecated.


There are other ways to do it, but based on comments from developers
I have seen in the past, abstime isn't going away any time soon.

One other approach would be to multiply a 1 second interval by the
timestamp and add it to a timestamp corresponding to the unix epoch
(00:00:00 on January 1, 1970 if I remember correctly). But your current
method is probably going to be faster.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #2

P: n/a
"Bruno BAGUETTE" <pg******@baguette.net> writes:
I'm looking for a way to convert a unix timestamp to a PostgreSQL date
without using ::abstime which seems to be deprecated.


abstime is not yet deprecated in my mind, precisely because it's still
the easiest way to do the reverse of "extract(epoch from timestamp)".
The cleanest alternative I know of is

select 'epoch'::timestamptz + (unixtimestamphere) * '1 sec'::interval;

but this still leaves an unsatisfied feeling. Sooner or later we'll
probably invent an explicit function to do this conversion.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #3

P: n/a
> Sooner or later we'll probably invent an explicit function to do this
conversion.


I may be wrong but why create a new fonction for unixtimestamp<-->date
conversion ?

I think that the to_date() function is the best place to add this kind
of conversion. Isn't it better to add a new value for the second
parameter of the to_date function ?

Regards,

---------------------------------------
Bruno BAGUETTE - pg******@baguette.net
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.