[MDEV-11890] Effect of NO_ZERO_DATE and NO_ZERO_IN_DATE is reversed Created: 2017-01-23 Updated: 2023-12-15 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Temporal Types |
| Affects Version/s: | 10.1, 10.2 |
| Fix Version/s: | 10.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Joe Cotellese |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The data and query example were taken from date_formats.test. I'm not sure SELECTs are supposed to be affected by NO_ZERO... modes at all, at least the manual doesn't say anything about it, it only mentions INSERTs.
However, assuming that SELECTs are also supposed to obey the modes, they seem to do it in an exactly opposite fashion:
Without any special modes, the query returns zero date:
It started happening in 10.1. MariaDB 10.0 has the reverse behavior, and so does MySQL 5.7:
|
| Comments |
| Comment by Elena Stepanova [ 2017-01-24 ] | ||||||||||||||||||||||
|
Setting to 10.2-ga in case these switches become a part of the new default sql_mode. If they don't, then there is no rush. | ||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-04-23 ] | ||||||||||||||||||||||
|
Removed 10.2-ga label since the switches didn't become a part of the default sql_mode. | ||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-04-18 ] | ||||||||||||||||||||||
|
Zero date is a date, datetime, timestamp value with all fields equal to 0:
However:
There is a difference between them, hence they have two separate sql_mode flags:
So in the above scripts it looks correct to:
| ||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-04-18 ] | ||||||||||||||||||||||
|
Hi KennethDyer, can you please make sure that 'zero date' and 'zero in date' are properly documented in the manual? Thanks. | ||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-04-18 ] | ||||||||||||||||||||||
|
More examples proving this behavior:
| ||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-04-18 ] | ||||||||||||||||||||||
|
bar,
It might be so in MariaDB now, and I am not going to argue which one is correct(er), but at least MySQL thinks differently about it. The quote in the description was from MySQL manual, and it's still basically the same in 8.0.
So, if it's intentional, KennethDyer, please have it documented not only as expected behavior, but as expected and intentional difference with MySQL (a.k.a. incompatibility). | ||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-04-18 ] | ||||||||||||||||||||||
|
MySQL manual is wrong. There is nothing special with year. In reality MySQL-5.7 works with DATE as follows:
So:
MariaDB works with DATEs exactly the same way. I've just checked how MariaDB-10.4.5 vs MySQL-5.7.25 work with DATETIME: NO_ZERO_IN_DATE+CAST work similar in MariaDB and MySQLThe following returns NULL, because it's not a zero date, but there are zeros in YYYY-MM-DD SET sql_mode=NO_ZERO_IN_DATE; NO_ZERO_DATE+INSERT work similar in MariaDB and MySQLSET sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE'; So the above disallows only '0000-00-00 00:00:00', which is a 'zero date'. NO_ZERO_IN_DATE+INSERT works similar in MariaDB and MySQLSET sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE'; The above script allows '0000-00-00 00:00:00', because it is 'zero date' (it is not 'zero in date'). So MySQL:
In MariaDB we made functions use the same rules for fields and for functions, and this was intentional. | ||||||||||||||||||||||
| Comment by Alexander Barkov [ 2019-04-23 ] | ||||||||||||||||||||||
|
Sorry, I overlooked that '0000-01-01' is not actually controlled by 'NO_ZERO_IN_DATE'. Just discussed with Serg. We agreed that this behavior is confusing. In 10.5 we'll fix NO_ZERO_IN_DATE to disallow '0000-01-01'. See ' | ||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2020-11-03 ] | ||||||||||||||||||||||
|
KennethDyer I inherited this task from Bar, could you say me what I have to review? | ||||||||||||||||||||||
| Comment by Daniel Black [ 2020-11-19 ] | ||||||||||||||||||||||
|
https://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=4802df2ee8bdd42f1b5107624a5189ea With NO_ZERO_IN_DATE, there a difference between:
If as bar says, functions and fields are the same. Should these be the same? | ||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2020-11-19 ] | ||||||||||||||||||||||
|
OK for me it will require long investigation (I have no idea what is going on with dates) |