2017-04-19 98 views

回答

1

我觉得这里是一个原因,这不会导致一个错误:

to_timestamp and to_date exist to handle input formats that cannot be converted by simple casting. These functions interpret input liberally, with minimal error checking. While they produce valid output, the conversion can yield unexpected results. For example, input to these functions is not restricted by normal ranges, thus to_date('20096040','YYYYMMDD') returns 2014-01-17 rather than causing an error. Casting does not have this behavior.

https://www.postgresql.org/docs/9.6/static/functions-formatting.html

+0

确定..感谢您的回答..但我真的一个当日期是错误的月份> 12为它返回一个错误示例和日期> 32 ..我该怎么做,或者我可以使用什么 – Kamfasage

+0

@Kamfasage - 如果您尝试投射'选择投射('20172202'作为日期)',您将收到错误 –

+0

,所以我应该这样做: 'select to_date(cast('20172202'as date),YYYYMMDD); ' 这不起作用,因为** to_date **函数具有参数文本和文本 – Kamfasage

0

我有什么,我想/ 我使用的TO_CHAR,而不是TO_DATE答案我把fisrt参数转换成日期..

select to_char(DATE '20162202,'YYYYMMDD') into datResult ; 

所以我现在可以有一个错误..

感谢您的帮助大家