需要将1/1000秒分辨率的时间戳转换为1/100分辨率。我可能会用to_char(timestamp, text)
用于此目的的格式化功能,但是需要帮助text
在这里使用。
输入表(注意 - 这里的时间戳存储为 varchar)
+-------------------------+
| ms1000_val |
+-------------------------+
| 2017/02/20 08:27:17.899 |
| 2017/02/20 08:23:43.894 |
| 2017/02/20 08:24:41.894 |
| 2017/02/20 08:28:09.899 |
+-------------------------+
输出表
+------------------------+
| ms100_val |
+------------------------+
| 2017/02/20 08:27:17.89 |
| 2017/02/20 08:23:43.89 |
| 2017/02/20 08:24:41.89 |
| 2017/02/20 08:28:09.89 |
+------------------------+
您可以在括号中指定它,如下所示:
t=# select now()::timestamp(2);
now
------------------------
2017-03-16 09:55:21.15
(1 row)
正如OP注意到的http://rextester.com/CBZ17212 http://rextester.com/CBZ17212产生不同的结果然后运行psql
:
t=# CREATE TABLE Table1
t-# ("ms1000_val" varchar(23))
t-# ;
CREATE TABLE
t=#
t=# INSERT INTO Table1
t-# ("ms1000_val")
t-# VALUES
t-# ('2017/02/20 08:27:17.892'),
t-# ('2017/02/20 08:23:43.891'),
t-# ('2017/02/20 08:24:41.897'),
t-# ('2017/02/20 08:28:09.893')
t-# ;
INSERT 0 4
t=# select ms1000_val::timestamp(2) as time_formatted
t-# from Table1;
time_formatted
------------------------
2017-02-20 08:27:17.89
2017-02-20 08:23:43.89
2017-02-20 08:24:41.9
2017-02-20 08:28:09.89
(4 rows)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)