将字符串转换为MonetDB中的时间戳

问题描述:

如何将字符串/ varchar转换为MonetDB中的时间戳?将字符串转换为MonetDB中的时间戳

这样,但精确到毫秒(6位小数,理想情况下):

sql>select str_to_date('2008-09-19-18.40.09.812000', '%Y-%m-%d-%H.%M.%6S'); 
+--------------------------+ 
| str_to_date_single_value | 
+==========================+ 
| 2008-09-19    | 
+--------------------------+ 
1 tuple (0.312ms) 

我不知道是否STR_TO_DATE内置或是否我创造了它很久很久以前,忘了。

create function str_to_date(s string, format string) returns date 
external name mtime."str_to_date"; 

编辑:预期的输出类似

+---------------------------------+ 
| str_to_timestamp_single_value | 
+=================================+ 
| 2008-09-19 18:40:09.812000  | 
+---------------------------------+ 

Monetdb时间转换函数中列出:

  • [Monetdb安装文件夹] \ monetDB5 \ LIB \ monetdb5 \ CREATEDB \ 13_date.sql。

除了str_to_date函数,还有一个str_to_timestamp函数。

格式字符串的语法如下the MySQL one

例子:

select sys.str_to_timestamp('2016-02-04 15:30:29', '%Y-%m-%d %H:%M:%S'); 
+0

对于monet v1.7,它会抛出'没有这样的二元运算符'错误。在函数名'select sys.str_to_timestamp'前添加模式名称 – redexp 2016-02-20 07:12:07

+0

感谢您的信息,我会更新我的答案。 – 2016-02-22 08:21:20

的日期/时间说明符可能需要改变:

select str_to_date('2008-09-19-18.40.09.812000','%Y-%m-%d-%H.%i.%s.%f') 

输出:

2008-09-19 18:40:09.812000 

* monetdb可能不同,尽管在标准SQL these are the standard date specifiers中。

你也可以使用date_format除了str_to_date

select date_format(str_to_date('SEP 19 2008 06:40:09:812PM','%M %D %Y %h:%i:%s:%f%p'),'%Y-%m-%d-%H.%i.%f'); 

输出:

2008-09-19-18.40.812000 
+0

日期/时间说明符都很好,我真的寻找类似'str_to_timestamp'。 – nacnudus 2014-11-15 02:26:31

+0

那么monetdb有处理精确时间的叫做'daytime'。如果我没有记错的话就像'daytime_tz_fromstr'。我想我有点不清楚,你的预期输出是什么? – 2014-11-15 02:29:43