select to_date('20170202','YYYYMMDD');
返回:
2017-02-02
但是当我这样做的时候:
select to_date('20172202','YYYYMMDD');
输出是:
2018-10-04
当月份错误时,为什么不像 Oracle 那样返回错误?
最佳答案
我认为这是不会导致错误的原因:
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
关于sql - postgresql 中的 to_date 函数如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498827/