Here is a table
CREATE TABLE `mytable` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`val` char(128) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY (val)
) ENGINE=InnoDB DEFAULT CHARSET=ascii;
Any idea why is this happening, I expected it to set id to zero in the first query itself
MariaDB > insert into mytable set id=0, val="" on duplicate key update id=0, val=val;
Query OK, 1 row affected (0.01 sec)
MariaDB > select * from mytable;
+----+-------+
| id | val |
+----+-------+
| 1 | |
+----+-------+
1 row in set (0.00 sec)
MariaDB > insert into mytable set id=0, val="" on duplicate key update id=0, val=val;
Query OK, 2 rows affected (0.01 sec)
MariaDB > select * from mytable;
+----+-------+
| id | val |
+----+-------+
| 0 | |
+----+-------+
1 row in set (0.00 sec)
MariaDB > insert into mytable set id=0, val="" on duplicate key update id=0, val=val;
Query OK, 0 rows affected (0.01 sec)
Any explanation will be appreciated.
Update: I am aware of using AUTO_INCREMENT=0 but the real question here is that query explicitly set id=0, so why it is setting it as 1 in first query. It seems mysql ok to set it 0 in duplicate instance.
Thanks