On Thu, Apr 04, 2013 at 04:17:26PM +0000, Abhinandan Prateek wrote:
> I was wondering that during a clean install the template.sql inserts these
> os types in DB and then runs the upgrade from 40 to 410.
> Since I added these os types in 40-410 it throws duplicate key exception.
> 
> I guess to fix this we need to remove this os type from the template
> instead of 40 to 410 upgrade script.
> 
> Rohit, since you restructured the upgrades, can you comment ?
> 
> -abhi

Actually, yes, insert ignore should work.  Here's how it behaves:

mysql> desc foo;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type                | Null | Key | Default | Extra          |
+-------+---------------------+------+-----+---------+----------------+
| id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| u     | int(11)             | YES  | UNI | NULL    |                |
+-------+---------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> insert into foo (id, u) values (3, 3);
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo;
+----+------+
| id | u    |
+----+------+
|  3 |    3 |
+----+------+
1 row in set (0.00 sec)

mysql> insert into foo (id, u) values (3, 3);
ERROR 1062 (23000): Duplicate entry '3' for key 'PRIMARY'

mysql> insert ignore into foo (id, u) values (3, 4);
Query OK, 0 rows affected (0.00 sec)

mysql> select * from foo;
+----+------+
| id | u    |
+----+------+
|  3 |    3 |
+----+------+
1 row in set (0.00 sec)

Reply via email to