STR_TO_DATE MySQL 5.5 和 MySQL 5.6 之间的差异
STR_TO_DATE discrepancy between MySQL 5.5 and MySQL 5.6
SQL returns MySQL 5.5 中的 DATE
但 MySQL 5.6 中的 NULL
。为什么?
select date(STR_TO_DATE('2015-01', '%Y-%m')) + INTERVAL 1 DAY;
这是 SQL Fiddle MySQL 5.5 and 5.6。 STR_TO_DATE
returns 两个实例中的日期。使用 DATE
转换结果有效。尝试添加 INTERVAL
时出现问题。我在STR_TO_DATE(...)
或DATE(STR_TO_DATE(...))
上加一个INTERVAL
都没有关系,结果是一样的。但是,删除 STR_TO_DATE
使其工作。
select
STR_TO_DATE('2015-01', '%Y-%m') as same_a1,
STR_TO_DATE('2015-01-01', '%Y-%m') as same_a2,
STR_TO_DATE('2015-01', '%Y-%m-%d') as same_a3,
STR_TO_DATE('2015-01-01', '%Y-%m-%d') as same_a4,
date(STR_TO_DATE('2015-01', '%Y-%m')) as same_b1,
date(STR_TO_DATE('2015-01-01', '%Y-%m')) as same_b2,
date(STR_TO_DATE('2015-01', '%Y-%m-%d')) as same_b3,
date(STR_TO_DATE('2015-01-01', '%Y-%m-%d')) as same_b4,
STR_TO_DATE('2015-01', '%Y-%m') + INTERVAL 1 DAY as same_c1,
STR_TO_DATE('2015-01-01', '%Y-%m') + INTERVAL 1 DAY as same_c2,
STR_TO_DATE('2015-01', '%Y-%m-%d') + INTERVAL 1 DAY as same_c3,
STR_TO_DATE('2015-01-01', '%Y-%m-%d') + INTERVAL 1 DAY as same_c4,
date(STR_TO_DATE('2015-01', '%Y-%m')) + INTERVAL 1 DAY as different_d1,
date(STR_TO_DATE('2015-01-01', '%Y-%m')) + INTERVAL 1 DAY as different_d2,
date(STR_TO_DATE('2015-01', '%Y-%m-%d')) + INTERVAL 1 DAY as different_d3,
date(STR_TO_DATE('2015-01-01', '%Y-%m-%d')) + INTERVAL 1 DAY as same_d4,
date('2015-01') + INTERVAL 1 DAY as same_e1,
date('2015-01-01') + INTERVAL 1 DAY as same_e2
;
我搜索了发行说明,但找不到任何内容。到底是怎么回事?这是一个已知的变化吗?错误?
这是一个已知的变化,无意中引入了版本 5.1.59, 5.5.16 and 5.6.3 (but was then rolled back in versions 5.1.62 and 5.5.21;它保留在 5.6 行中):
Incompatible Change: Handling of a date-related assertion was modified.
However, a consequence of this change is that several functions become more strict when passed a DATE()
function value as their argument and reject incomplete dates with a day part of zero. These functions are affected: CONVERT_TZ()
, DATE_ADD()
, DATE_SUB()
, DAYOFYEAR()
, LAST_DAY()
, TIMESTAMPDIFF()
, TO_DAYS()
, TO_SECONDS()
, WEEK()
, WEEKDAY()
, WEEKOFYEAR()
, YEARWEEK()
. Because this changes date-handling behavior in General Availability-status series (MySQL 5.1 and 5.5), it was reverted in 5.1.62 and 5.5.21. The change is retained in MySQL 5.6.
References: See also Bug #13458237.
您受到了影响,因为 + INTERVAL
符号只是 DATE_ADD()
函数周围的语法糖。
SQL returns MySQL 5.5 中的 DATE
但 MySQL 5.6 中的 NULL
。为什么?
select date(STR_TO_DATE('2015-01', '%Y-%m')) + INTERVAL 1 DAY;
这是 SQL Fiddle MySQL 5.5 and 5.6。 STR_TO_DATE
returns 两个实例中的日期。使用 DATE
转换结果有效。尝试添加 INTERVAL
时出现问题。我在STR_TO_DATE(...)
或DATE(STR_TO_DATE(...))
上加一个INTERVAL
都没有关系,结果是一样的。但是,删除 STR_TO_DATE
使其工作。
select
STR_TO_DATE('2015-01', '%Y-%m') as same_a1,
STR_TO_DATE('2015-01-01', '%Y-%m') as same_a2,
STR_TO_DATE('2015-01', '%Y-%m-%d') as same_a3,
STR_TO_DATE('2015-01-01', '%Y-%m-%d') as same_a4,
date(STR_TO_DATE('2015-01', '%Y-%m')) as same_b1,
date(STR_TO_DATE('2015-01-01', '%Y-%m')) as same_b2,
date(STR_TO_DATE('2015-01', '%Y-%m-%d')) as same_b3,
date(STR_TO_DATE('2015-01-01', '%Y-%m-%d')) as same_b4,
STR_TO_DATE('2015-01', '%Y-%m') + INTERVAL 1 DAY as same_c1,
STR_TO_DATE('2015-01-01', '%Y-%m') + INTERVAL 1 DAY as same_c2,
STR_TO_DATE('2015-01', '%Y-%m-%d') + INTERVAL 1 DAY as same_c3,
STR_TO_DATE('2015-01-01', '%Y-%m-%d') + INTERVAL 1 DAY as same_c4,
date(STR_TO_DATE('2015-01', '%Y-%m')) + INTERVAL 1 DAY as different_d1,
date(STR_TO_DATE('2015-01-01', '%Y-%m')) + INTERVAL 1 DAY as different_d2,
date(STR_TO_DATE('2015-01', '%Y-%m-%d')) + INTERVAL 1 DAY as different_d3,
date(STR_TO_DATE('2015-01-01', '%Y-%m-%d')) + INTERVAL 1 DAY as same_d4,
date('2015-01') + INTERVAL 1 DAY as same_e1,
date('2015-01-01') + INTERVAL 1 DAY as same_e2
;
我搜索了发行说明,但找不到任何内容。到底是怎么回事?这是一个已知的变化吗?错误?
这是一个已知的变化,无意中引入了版本 5.1.59, 5.5.16 and 5.6.3 (but was then rolled back in versions 5.1.62 and 5.5.21;它保留在 5.6 行中):
Incompatible Change: Handling of a date-related assertion was modified.
However, a consequence of this change is that several functions become more strict when passed a
DATE()
function value as their argument and reject incomplete dates with a day part of zero. These functions are affected:CONVERT_TZ()
,DATE_ADD()
,DATE_SUB()
,DAYOFYEAR()
,LAST_DAY()
,TIMESTAMPDIFF()
,TO_DAYS()
,TO_SECONDS()
,WEEK()
,WEEKDAY()
,WEEKOFYEAR()
,YEARWEEK()
. Because this changes date-handling behavior in General Availability-status series (MySQL 5.1 and 5.5), it was reverted in 5.1.62 and 5.5.21. The change is retained in MySQL 5.6.References: See also Bug #13458237.
您受到了影响,因为 + INTERVAL
符号只是 DATE_ADD()
函数周围的语法糖。