Please find attached a patch (diff -c against cvs HEAD) to add a
authorBruce Momjian
Thu, 9 Jun 2005 16:35:09 +0000 (16:35 +0000)
committerBruce Momjian
Thu, 9 Jun 2005 16:35:09 +0000 (16:35 +0000)
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

doc/src/sgml/func.sgml
src/include/catalog/pg_proc.h

index 7eb2c4c6b135dfd27e9851e4e7afd46511dd417a..bc34c96542c4e6dd088483311a3b213c21c3a8b1 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -4082,6 +4082,13 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
     argument is the value to be formatted and the second argument is a
     template that defines the output or input format.
    
+   
+    The to_timestamp function can also take a single 
+    double precision argument to convert from Unix epoch to 
+    timestamp with time zone.
+    (Integer Unix epochs are implicitly cast to 
+    double precision.)
+   
 
     
      Formatting Functions
@@ -4138,6 +4145,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
         convert string to time stamp
         to_timestamp('05 Dec 2000', 'DD Mon YYYY')
        
+       
+        to_timestamp(double precision)
+        timestamp with time zone
+        convert UNIX epoch to time stamp
+        to_timestamp(200120400)
+       
        
         to_number(texttext)
         numeric
index 9f5c2d8e0e3dc061db8a7a96bbb7e4811daae6b8..5bf7753dcea661f1f0b0d1da31a9856963f0d269 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.364 2005/06/07 07:08:34 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.365 2005/06/09 16:35:09 momjian Exp $
  *
  * NOTES
  *   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
 DESCR("greater-than-or-equal");
 DATA(insert OID = 1157 (  timestamptz_gt   PGNSP PGUID 12 f f t f i 2 16 "1184 1184" _null_ _null_ _null_ timestamp_gt - _null_ ));
 DESCR("greater-than");
+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_ ));
+DESCR("convert UNIX epoch to timestamptz");
 DATA(insert OID = 1159 (  timezone        PGNSP PGUID 12 f f t f i 2 1114 "25 1184" _null_ _null_ _null_  timestamptz_zone - _null_ ));
 DESCR("adjust timestamp to new time zone");