需要将时间戳以1/1000秒分辨率转换为1/100分辨率。我可以为此目的使用to_char(timestamp, text)
格式化功能,但是需要帮助才能使用text
。 Postgres这样做的方法是here。
输入表(注意 - 此处的时间戳存储为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 |
+------------------------+
答案 0 :(得分:1)
试试这个
select cast(to_char(sub.field,'YYYY-MM-DD HH24:MI:SS') as timestamp)
+ interval '10 millisecond' * (cast(to_char(sub.field,'MS') as integer)/10) as converted_value
from (
select to_timestamp('2017/02/20 08:27:17.899','YYYY/MM/DD HH24:MI:SS.MS') as field
union
select to_timestamp('2017/02/20 08:23:43.894','YYYY/MM/DD HH24:MI:SS.MS')
union
select to_timestamp('2017/02/20 08:24:41.894','YYYY/MM/DD HH24:MI:SS.MS')
union
select to_timestamp('2017/02/20 08:28:09.899','YYYY/MM/DD HH24:MI:SS.MS')
) sub