无法从时间戳中删除毫秒

问题描述 投票:0回答:1

我把这个

date_created
作为
2015-12-02 00:58:07.000000
。 所以我已经在 SO 和 Google 上搜索了一段时间,现在我已经尝试了一切,感觉就像......

date_created::timestamp(0)

to_char(date_created, 'YYYY-MM-DD HH24:MI:SS')::timestamp(0)

DATE_TRUNC('second', date_created)::timestamp(0)
返回

[XX000] ERROR: Assert
Detail: ----------------------------------------------- error:
Assert code: 1 ...

...

to_timestamp(date_created)::timestamp(0)
回归

[42883] ERROR: function to_timestamp(timestamp without time zone) does not exist
Hint: No function matches the given name and argument types. You may need to add explicit type casts.

...

date_trunc('minute', date_created::timestamp)

date_trunc('minute', date_created)
返回

2015-12-02 00:58:00.000000

我只想降到愚蠢的毫秒,同时仍将数据类型保持为日期时间或时间戳。有人还有其他技巧吗?或者这根本就是不可能的事?

postgresql datetime timestamp amazon-redshift
1个回答
0
投票

影响 PostgreSQL 将时间戳呈现为字符串的方式的唯一方法是设置参数

datestyle
,并且任何设置都不会抑制秒小数部分的显示。

如果您对将时间戳呈现为字符串有特殊要求,请像第二次尝试一样使用

to_char
,但省略对
timestamp
的额外转换,因为它会抵消您的努力。

© www.soinside.com 2019 - 2024. All rights reserved.