Re: New function: epoch_to_timestamp... - Mailing list pgsql-hackers

From Tom Lane
Subject Re: New function: epoch_to_timestamp...
Date
Msg-id 24487.1061037876@sss.pgh.pa.us
Whole thread Raw
In response to Re: New function: epoch_to_timestamp...  (David Fetter <david@fetter.org>)
List pgsql-hackers
David Fetter <david@fetter.org> writes:
> [code]

Seems pretty messy.  I believe the standard way of doing this is

regression=# create function epoch_to_timestamp(float8) returns timestamptz as '
regression'# begin
regression'#   return ''epoch''::timestamptz + $1 * ''1 second''::interval;
regression'# end' language plpgsql strict immutable;
CREATE FUNCTION

regression=# select now(), extract(epoch from now());             now              |    date_part
-------------------------------+-----------------2003-08-16 08:43:16.925501-04 | 1061037796.9255
(1 row)

regression=# select epoch_to_timestamp(1061037796.9255);    epoch_to_timestamp
-----------------------------2003-08-16 08:43:16.9255-04
(1 row)

        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: full path infrastructure for DT_SONAME?
Next
From: ivan
Date:
Subject: CREATE TYPE