Convert "epoch" to timestamp

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Convert "epoch" to timestamp
Date: 2002-04-23 14:33:23
Message-ID: 20020423143323.33105.qmail@web20801.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jeff=# select version();
version

-------------------------------------------------------------------
PostgreSQL 7.2 on i386-portbld-freebsd4.5, compiled
by GCC 2.95.3
(1 row)

I need to convert the "epoch" (i.e. number of seconds)
timestamp to a PostgreSQL timestamp.

The extract/date_part functions do it easily the other
way, but I have had some difficulty in doing what I
need.

According to posts in the archives, the following used
to work:

jeff=# select extract (epoch from
current_timestamp(0));
date_part
------------
1019571752
(1 row)

jeff=# select timestamp(1019571752);
ERROR: TIMESTAMP(1019571752) WITH TIME ZONE precision
must be between 0 and 13
jeff=#

I assume this change came with the other date/time
changes in version 7.2.

The following works:

jeff=# select abstime(1019571752);
abstime
------------------------
2002-04-23 09:22:32-05
(1 row)

Can I rely on this continuing to work? Apparently
not, because the docs say (wrt "abstime" and
"reltime"): "Any or all of these internal types might
disappear in a future release."

Is there another/better way?

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alejandro Fernandez 2002-04-23 14:51:40 Connections per second?
Previous Message Ian Cass 2002-04-23 14:07:49 Re: Date indexing