Postgres timestamp with microseconds

拜拜、爱过 提交于 2021-02-11 12:18:28

问题


I have a column in a table with datatype set as timestamp without time zone.

I need the time part with microseconds(6 digits), but sometimes if the last digit is zero, the microseconds part ignores it.

I am able to query it with the below query to get 6 digits select to_char(now(), 'yyyy-mm-dd hh:mi:us'); 2020-07-16 12:05:598000

The above output is in text/char format but I need it in timestamp without time zone datatype with all 6 digits for microseconds even if one or some of the last digits are zero. The column datatype is timestamp without time zone


回答1:


The number of significant digits does not come into play until you attempt to display the value. In this example, 46.392000 is equivalent to 46.392 just as it is with decimal numbers.

select '2020-07-16 11:35:46.392000-4'::timestamptz = '2020-07-16 11:35:46.392-4'::timestamptz;

 ?column? 
----------
 t

Where is it that you need to see all six digits with the dropped zeros? That is where you need to apply the formatting.



来源:https://stackoverflow.com/questions/62937930/postgres-timestamp-with-microseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!