[MDEV-32474] INSERT .. DEFAULT broken when when columns are out of order Created: 2023-10-13 Updated: 2023-10-13 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Insert |
| Affects Version/s: | 10.4, 10.5, 10.6, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Zach Musgrave | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Defining a column default that refers to a column earlier in the schema doesn't work when using the DEFAULT keyword in insert statements if the set of insert columns is given in a different order than table schema order. Repro:
Expected result is [3,4] MySQL has the same bug, which they deny is a bug: https://bugs.mysql.com/bug.php?id=112708 I wrote a blog post about why I think that's the wrong call here: https://www.dolthub.com/blog/2023-10-13-fixing-mysql-bugs-in-dolt/ |
| Comments |
| Comment by Sergei Golubchik [ 2023-10-13 ] | ||||||||||||||||||
|
commenting on your blog and MySQL's bug resolution
and
<datetime value function> is CURRENT_TIMESTAMP and alikes, and <implicitly typed value specification> is NULL and empty array or multiset. That's all, no expressions with column references. | ||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-10-13 ] | ||||||||||||||||||
|
Currently it works pretty much as
and in line with MySQL's left-to-right evaluation it does what it does. Consider, that you can do
and neither MariaDB nor MySQL will not scream at you for this. Left-to-right allows to resolve all that. As helpful as comparing an integer and a string, isn't it? Technically it's possible not to do left-to-right in INSERT, MariaDB has a special sql_mode for that. But then we need to figure out what to do with all those cases of circular dependencies like above, how to detect them, what the result should be, etc. | ||||||||||||||||||
| Comment by Zach Musgrave [ 2023-10-13 ] | ||||||||||||||||||
|
Very interesting context, thank you for following up! | ||||||||||||||||||
| Comment by Zach Musgrave [ 2023-10-13 ] | ||||||||||||||||||
|
Considering that you're kind of off-the-map with respect to the SQL standard, you guys could take this in several directions, eager to see what you think. From a developer perspective, I would naively think the following three statements should be equivalent: insert into t1(a) values (3); The fact that these produce different results is confusing in my opinion, although I better understand why the third behaves differently now. |