From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org> |
Subject: | Epoch to timestamp conversion function patch |
Date: | 2004-08-03 03:40:08 |
Message-ID: | D0B37D85-E4FE-11D8-8966-000A95C88220@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Please find attached two patches (one for pg_proc.h and another for
supporting documentation) for two SQL functions:
epoch_to_timestamp(integer) and epoch_to_timestamptz(double precision),
which convert from UNIX epoch to the native PostgreSQL timestamp and
timestamptz data types. The equivalent SQL code is
create function epoch_to_timestamp(integer)
returns timestamp
language sql as '
select (\'epoch\'::timestamptz + $1 * \'1
second\'::interval)::timestamp
';
create function epoch_to_timestamptz(double precision)
returns timestamptz
language sql as '
select (\'epoch\'::timestamp + $1 * \'1 second\'::interval) at time
zone \'UTC\'
';
Some very simple tests (all should return TRUE):
test=# select epoch_to_timestamp(extract(epoch from
current_timestamp)::integer) = current_timestamp::timestamp(0);
?column?
----------
t
(1 row)
test=# select epoch_to_timestamptz(extract(epoch from
current_timestamp)::integer) = current_timestamp(0);
?column?
----------
t
(1 row)
test=# select epoch_to_timestamptz(extract(epoch from
current_timestamp)) = current_timestamp;
?column?
----------
t
(1 row)
If regression tests are desired, I'll work some up. Any feedback
appreciated.
Michael Glaesemann
grzm myrealbox com
Attachment | Content-Type | Size |
---|---|---|
func.sgml.diff | application/octet-stream | 2.7 KB |
pg_proc.h.diff | application/octet-stream | 1.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew T. O'Connor | 2004-08-03 03:41:49 | Re: autovauum integration patch: Attempt #4 |
Previous Message | Christopher Kings-Lynne | 2004-08-03 02:54:34 | Re: psql latex bugfixes |