[MDEV-24691] sql_mode NO_ZERO_DATE conflicts with versioned tables Created: 2021-01-26 Updated: 2021-04-13 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.5.8 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Remy Fox | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The sql_mode variable NO_ZERO_DATE specifies to reject any INSERT and UPDATE queries where a date value is submitted as '0000-00-00'. Though if a new column is added to a table, then the value '0000-00-00' is still inserted for all rows. It is a session variable and not an attribute of the table column, which causes problems if the sql mode is entered after a table has been created. For example: 1:
Now the following ALTER TABLE will fail, despite that it does not touch column 'a'.
This is especially apparent in versioned tables. Both these situations will cause error code 1067: 2:
3:
Given that '0000-00-00' values can still occur in a table, despite that NO_ZERO_DATE may at one point in time become configured, I think that a column's default value should not be validated against this restriction, especially when a table alteration does not even affect that column. Perhaps an even better solution would be to make NO_ZERO_DATE an attribute of the column, rather than a session variable. |
| Comments |
| Comment by Elena Stepanova [ 2021-01-31 ] |
|
Which server version are you using? |
| Comment by Remy Fox [ 2021-01-31 ] |
|
I tested on 10.4.10 and 10.5.8. It turns out that the first error happens on both version, while the second and third example no longer exist in 10.5.8. |
| Comment by Elena Stepanova [ 2021-01-31 ] |
|
Right, The behavior with CREATE/ALTER table is expected. It is a documentation bug if you point out at the documentation page which you refer to as "The sql_mode variable NO_ZERO_DATE specifies to reject any INSERT and UPDATE queries where a date value is submitted as '0000-00-00'." I can't find it either in MariaDB KB or in MySQL manual. Both do say that INSERT/UPDATE IGNORE allow to bypass the restriction, but it doesn't mean that the restriction only applies to INSERT/UPDATE. |
| Comment by Remy Fox [ 2021-01-31 ] |
|
Why is the ALTER TABLE expected to fail when I add a totally unrelated column to an empty table under this configuration? |