can be discussed
The initially suggested ROW_NUMBER was intuitively understandable, but ERROR_INDEX in the final implementation is not. It is not necessarily an error, and it is certainly not its index.
MariaDB [test]> insert ignore into t1 (pk) values (1),(1);
|
Query OK, 1 row affected, 1 warning (0.017 sec)
|
Records: 2 Duplicates: 1 Warnings: 1
|
|
MariaDB [test]> show warnings;
|
+---------+------+---------------------------------------+
|
| Level | Code | Message |
|
+---------+------+---------------------------------------+
|
| Warning | 1062 | Duplicate entry '1' for key 'PRIMARY' |
|
+---------+------+---------------------------------------+
|
1 row in set (0.000 sec)
|
|
MariaDB [test]> get diagnostics condition 1 @num = ERROR_INDEX, @msg = MESSAGE_TEXT; select @num, @msg;
|
Query OK, 0 rows affected (0.000 sec)
|
|
+------+---------------------------------------+
|
| @num | @msg |
|
+------+---------------------------------------+
|
| 2 | Duplicate entry '1' for key 'PRIMARY' |
|
+------+---------------------------------------+
|
1 row in set (0.000 sec)
|
If something is an "index" here, it's the condition number (1), but the failing row number is 2. And it's a warning.