sql - postgresql 中的 to_date 函数如何工作?

标签 sql postgresql to-date

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/

相关文章:

sql - 为什么 ORACLE TO_DATE 函数在传递空格时不会在 OR 条件中给出 ORA-01841 错误?

sql - 将所有选定的列转换为_char

postgresql - `@@` 在 PostgreSQL 查询中意味着什么?

sql - 在非不同索引上使用递归 cte 计算不同行

postgresql - 在 postgres 中标准化日期 - 迄今为止的字符

MySQL - 用于日期比较的 Where 子句

postgresql - Postgres 选择 'at least' 项

MySQL:如果在什么地方?

mysql - View 选择语句可以包含另一个 View 吗?

sql - 如何防止查询中出现惰性后台打印?