Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4d0e7b4

Browse files
committed
Please find attached a patch (diff -c against cvs HEAD) to add a
function that accepts a double precision argument assumed to be a Unix epoch timestamp and returns timestamp with time zone, and accompanying documentation. Usage: test=# select to_timestamp(200120400); to_timestamp ------------------------ 1976-05-05 14:00:00+09 (1 row) Michael Glaesemann
1 parent 4a5cda7 commit 4d0e7b4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

doc/src/sgml/func.sgml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.252 2005/06/07 07:08:34 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.253 2005/06/09 16:35:08 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -4082,6 +4082,13 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
40824082
argument is the value to be formatted and the second argument is a
40834083
template that defines the output or input format.
40844084
</para>
4085+
<para>
4086+
The <function>to_timestamp</function> function can also take a single
4087+
<type>double precision</type> argument to convert from Unix epoch to
4088+
<type>timestamp with time zone</type>.
4089+
(<type>Integer</type> Unix epochs are implicitly cast to
4090+
<type>double precision</type>.)
4091+
</para>
40854092

40864093
<table id="functions-formatting-table">
40874094
<title>Formatting Functions</title>
@@ -4138,6 +4145,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
41384145
<entry>convert string to time stamp</entry>
41394146
<entry><literal>to_timestamp('05&nbsp;Dec&nbsp;2000', 'DD&nbsp;Mon&nbsp;YYYY')</literal></entry>
41404147
</row>
4148+
<row>
4149+
<entry><literal><function>to_timestamp</function>(<type>double precision</type>)</literal></entry>
4150+
<entry><type>timestamp with time zone</type></entry>
4151+
<entry>convert UNIX epoch to time stamp</entry>
4152+
<entry><literal>to_timestamp(200120400)</literal></entry>
4153+
</row>
41414154
<row>
41424155
<entry><literal><function>to_number</function>(<type>text</type>, <type>text</type>)</literal></entry>
41434156
<entry><type>numeric</type></entry>

src/include/catalog/pg_proc.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.364 2005/06/07 07:08:34 neilc Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.365 2005/06/09 16:35:09 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1459,6 +1459,8 @@ DATA(insert OID = 1156 ( timestamptz_ge PGNSP PGUID 12 f f t f i 2 16 "1184 1
14591459
DESCR("greater-than-or-equal");
14601460
DATA(insert OID = 1157 ( timestamptz_gt PGNSP PGUID 12 f f t f i 2 16 "1184 1184" _null_ _null_ _null_ timestamp_gt - _null_ ));
14611461
DESCR("greater-than");
1462+
DATA(insert OID = 1158 ( to_timestamp PGNSP PGUID 14 f f t f i 1 1184 "701" _null_ _null_ _null_ "select (\'epoch\'::timestamptz + $1 * \'1 second\'::interval)" - _null_ ));
1463+
DESCR("convert UNIX epoch to timestamptz");
14621464
DATA(insert OID = 1159 ( timezone PGNSP PGUID 12 f f t f i 2 1114 "25 1184" _null_ _null_ _null_ timestamptz_zone - _null_ ));
14631465
DESCR("adjust timestamp to new time zone");
14641466

0 commit comments

Comments
 (0)