Re: definative way to place secs from epoc into timestamp - Mailing list pgsql-sql

From Tom Lane
Subject Re: definative way to place secs from epoc into timestamp
Date
Msg-id 17735.1109831102@sss.pgh.pa.us
Whole thread Raw
In response to Re: definative way to place secs from epoc into timestamp  (Bret Hughes <bhughes@elevating.com>)
Responses Re: definative way to place secs from epoc into timestamp
List pgsql-sql
Bret Hughes <bhughes@elevating.com> writes:
> create function int2ts(integer) returns timestamp  as '
> SELECT ( TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * INTERVAL \'1
> second\')::timestamp without time zone;
> ' language sql;

> create function ts2int(timestamp without time zone) returns int as '
> select extract( \'epoch\' from $1)::integer;
> ' language sql;

Looks good as far as it goes.  Two thoughts:

* both functions should probably be marked STRICT STABLE
(not IMMUTABLE, because they depend on the local timezone setting).

* have you considered allowing the numeric values to be float8 instead
of integer?  There doesn't seem any reason to disallow sub-second
precision.
        regards, tom lane


pgsql-sql by date:

Previous
From: Bret Hughes
Date:
Subject: Re: definative way to place secs from epoc into timestamp
Next
From: Michael Glaesemann
Date:
Subject: Re: definative way to place secs from epoc into timestamp