Afficher un message
Vieux 18/10/2007, 11h28   #1
fmardini
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut bug with insert select?

I think I might have found a bug with insert select when inserting
into the same table and using a composite primary key
I made the smallest example I could come up with

CREATE TABLE `t1` (
`id1` int(11) NOT NULL,
`id2` int(11) NOT NULL,
`val1` int(11) default '0',
`val2` int(11) default '0',
PRIMARY KEY (`id1`,`id2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

CREATE VIEW t1v AS SELECT * FROM t1

INSERT INTO t1 (`id1`, `id2`, `val1`, `val2`) VALUES (1, 1, 1, 10),
(1, 2, 2, 20), (1, 3, 3, 30), (2, 1, 1, 40), (2, 2, 2, 50), (2, 3, 3,
60)

I want to insert into the table from itself
I use the view as a way to reference the selected row as opposed to
the found (duplicate) row (otherwise i get an ambiguous reference
error)

INSERT INTO t1
SELECT 1, id2, 0, 100
FROM t1v WHERE id1 = 2
ON DUPLICATE KEY UPDATE t1.val2 = t1v.val1 + 100

After executing the query, the contents of the table are

1 1 1 103
1 2 2 103
1 3 3 103
2 1 1 40
2 2 2 50
2 3 3 60

I was expecting the following

1 1 1 101
1 2 2 102
1 3 3 103
2 1 1 40
2 2 2 50
2 3 3 60

Am I doing something wrong or is this a bug with INSERT SELECT
If this is the wrong list, please tell me where to post

thanks
fmardini

  Réponse avec citation
 
Page generated in 0,06458 seconds with 9 queries