Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
Updated patch attached with both documentation portions --- applied. --- Michael Glaesemann wrote: 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) If regression tests are required, I will produce some. I'd appreciate any pointers as to what to look for, as they would be my first attempt at writing regression tests. Regards Michael Glaesemann grzm myrealbox com [ Attachment, skipping... ] ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send unregister YourEmailAddressHere to [EMAIL PROTECTED]) -- Bruce Momjian| http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 Index: doc/src/sgml/func.sgml === RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.252 diff -c -c -r1.252 func.sgml *** doc/src/sgml/func.sgml 7 Jun 2005 07:08:34 - 1.252 --- doc/src/sgml/func.sgml 9 Jun 2005 16:33:38 - *** *** 4082,4087 --- 4082,4094 argument is the value to be formatted and the second argument is a template that defines the output or input format. /para +para + The functionto_timestamp/function function can also take a single + typedouble precision/type argument to convert from Unix epoch to + typetimestamp with time zone/type. + (typeInteger/type Unix epochs are implicitly cast to + typedouble precision/type.) +/para table id=functions-formatting-table titleFormatting Functions/title *** *** 4139,4144 --- 4146,4157 entryliteralto_timestamp('05nbsp;Decnbsp;2000', 'DDnbsp;Monnbsp;')/literal/entry /row row + entryliteralfunctionto_timestamp/function(typedouble precision/type)/literal/entry + entrytypetimestamp with time zone/type/entry + entryconvert UNIX epoch to time stamp/entry + entryliteralto_timestamp(200120400)/literal/entry +/row +row entryliteralfunctionto_number/function(typetext/type, typetext/type)/literal/entry entrytypenumeric/type/entry entryconvert string to numeric/entry Index: src/include/catalog/pg_proc.h === RCS file: /cvsroot/pgsql/src/include/catalog/pg_proc.h,v retrieving revision 1.364 diff -c -c -r1.364 pg_proc.h *** src/include/catalog/pg_proc.h 7 Jun 2005 07:08:34 - 1.364 --- src/include/catalog/pg_proc.h 9 Jun 2005 16:33:45 - *** *** 1459,1464 --- 1459,1466 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); ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
This has been saved for the 8.1 release: http:/momjian.postgresql.org/cgi-bin/pgpatches2 --- Michael Glaesemann wrote: 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) If regression tests are required, I will produce some. I'd appreciate any pointers as to what to look for, as they would be my first attempt at writing regression tests. Regards Michael Glaesemann grzm myrealbox com [ Attachment, skipping... ] ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send unregister YourEmailAddressHere to [EMAIL PROTECTED]) -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
On Aug 15, 2004, at 1:19 AM, Tom Lane wrote: There was however another patch submitted recently that seemed to duplicate yours functionally but used a different syntax --- I think the guy had started by looking at extract(epoch from timestamp) rather than to_timestamp. Other than Chris' suggestion of extract(timestamp from epoch)? I did find this documentation patch from December 2003 giving an example of how to convert from Unix epoch to timestamp, but not a function per se. http://archives.postgresql.org/pgsql-patches/2003-12/msg00112.php However, I suspect you may thinking of something else. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
Michael Glaesemann [EMAIL PROTECTED] writes: On Aug 15, 2004, at 1:19 AM, Tom Lane wrote: There was however another patch submitted recently that seemed to duplicate yours functionally but used a different syntax --- I think Other than Chris' suggestion of extract(timestamp from epoch)? [ looks in archives... ] Oh, actually that was *you* --- I was vaguely remembering your proposed patch of 2-Aug. You were calling the function epoch_to_timestamp at the time. I like to_timestamp(double) better than these other names ... regards, tom lane ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
TODO here? --- Tom Lane wrote: Michael Glaesemann [EMAIL PROTECTED] writes: On Aug 15, 2004, at 1:19 AM, Tom Lane wrote: There was however another patch submitted recently that seemed to duplicate yours functionally but used a different syntax --- I think Other than Chris' suggestion of extract(timestamp from epoch)? [ looks in archives... ] Oh, actually that was *you* --- I was vaguely remembering your proposed patch of 2-Aug. You were calling the function epoch_to_timestamp at the time. I like to_timestamp(double) better than these other names ... regards, tom lane ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [PATCHES] to_timestamp overloaded to convert from Unix epoch
Sorry, I now see I should add the patch to the 8.1 queue. --- Bruce Momjian wrote: TODO here? --- Tom Lane wrote: Michael Glaesemann [EMAIL PROTECTED] writes: On Aug 15, 2004, at 1:19 AM, Tom Lane wrote: There was however another patch submitted recently that seemed to duplicate yours functionally but used a different syntax --- I think Other than Chris' suggestion of extract(timestamp from epoch)? [ looks in archives... ] Oh, actually that was *you* --- I was vaguely remembering your proposed patch of 2-Aug. You were calling the function epoch_to_timestamp at the time. I like to_timestamp(double) better than these other names ... regards, tom lane ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
[PATCHES] to_timestamp overloaded to convert from Unix epoch
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) If regression tests are required, I will produce some. I'd appreciate any pointers as to what to look for, as they would be my first attempt at writing regression tests. Regards Michael Glaesemann grzm myrealbox com to_timestamp.diff Description: Binary data ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send unregister YourEmailAddressHere to [EMAIL PROTECTED])