netezza - 将时间戳格式化为 1/100 秒/1/10 秒
netezza - formatting timestamp to 1/100s / 1/10s of seconds
我可以按如下方式将时间戳格式化为秒。
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS') --> 2017-02-20 08:22:44
我需要把上面的时间戳格式化成100s和10s秒
--> 2017-02-20 08:22:44.17
(格式化为 1/100 秒)
--> 2017-02-20 08:22:44.2
(格式化为 1/10 秒)
我尝试了如下的 postgres 方法,但这会在我使用的 Netezza 平台中出现错误
select '2017-02-20 08:22:44.166'::timestamp(2), '2017-02-20 08:22:44.166'::timestamp(1);
ERROR [42000] ERROR: 'select '2017-02-20 08:22:44.166'::timestamp(2), '2017-02-20 08:22:44.166'::timestamp(1) LIMIT 1000'
error ^ found "(" (at char 44) expecting a keyword
这不是很漂亮,但它确实适用于 PostgreSQL,我相信它也适用于 Netezza。 (不幸的是,我无法再访问 Netezza 框,所以我只能依赖文档):
select
'2017-02-20 08:22:44.166'::timestamp,
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS.') ||
round(to_char('2017-02-20 08:22:44.166'::timestamp, 'MS')::float / 10) as hundredths,
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS.') ||
round(to_char('2017-02-20 08:22:44.166'::timestamp, 'MS')::float / 100) as tenths;
timestamp | hundredths | tenths
-------------------------+------------------------+-----------------------
2017-02-20 08:22:44.166 | 2017-02-20 08:22:44.17 | 2017-02-20 08:22:44.2
(1 row)
我可以按如下方式将时间戳格式化为秒。
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS') --> 2017-02-20 08:22:44
我需要把上面的时间戳格式化成100s和10s秒
--> 2017-02-20 08:22:44.17
(格式化为 1/100 秒)
--> 2017-02-20 08:22:44.2
(格式化为 1/10 秒)
我尝试了如下的 postgres 方法,但这会在我使用的 Netezza 平台中出现错误
select '2017-02-20 08:22:44.166'::timestamp(2), '2017-02-20 08:22:44.166'::timestamp(1);
ERROR [42000] ERROR: 'select '2017-02-20 08:22:44.166'::timestamp(2), '2017-02-20 08:22:44.166'::timestamp(1) LIMIT 1000'
error ^ found "(" (at char 44) expecting a keyword
这不是很漂亮,但它确实适用于 PostgreSQL,我相信它也适用于 Netezza。 (不幸的是,我无法再访问 Netezza 框,所以我只能依赖文档):
select
'2017-02-20 08:22:44.166'::timestamp,
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS.') ||
round(to_char('2017-02-20 08:22:44.166'::timestamp, 'MS')::float / 10) as hundredths,
to_char('2017-02-20 08:22:44.166'::timestamp, 'YYYY-MM-DD HH24:MI:SS.') ||
round(to_char('2017-02-20 08:22:44.166'::timestamp, 'MS')::float / 100) as tenths;
timestamp | hundredths | tenths
-------------------------+------------------------+-----------------------
2017-02-20 08:22:44.166 | 2017-02-20 08:22:44.17 | 2017-02-20 08:22:44.2
(1 row)