Unexpected mysql behavior when inserting new rows -


i've got query:

insert series_measures (sensor_sid,dataset_sid,created_on)  values (841468,145,'2016-10-26 11:36:07'), ... ,(841505,145,'2016-10-26 11:36:07')  on duplicate key update sensor_sid=values(sensor_sid),dataset_sid=values(dataset_sid),created_on=values(created_on); 

two things don't understand happening here:

a. if (sensor_sid-dataset_sid) inserted:

error:

duplicate entry '145-841468' key 'fk_series_meas_dataset_idx'

but on duplicate key update should avoid that.

b. if (sensor_sid-dataset_sid) not inserted yet:

error:

duplicate entry '412870' key 'primary'

primary sid, has auto-increment (see create statement below), makes no sense me.


this create statement of table:

create table `series_measures` (   `sid` bigint(20) unsigned not null auto_increment,   `sensor_sid` int(10) unsigned not null,   `dataset_sid` int(10) unsigned not null,   `created_on` timestamp not null default current_timestamp,   primary key (`sid`),   unique key `fk_series_meas_dataset_idx` (`dataset_sid`,`sensor_sid`),   key `fk_series_meas_sensor_idx` (`sensor_sid`),   constraint `fk_series_meas_dataset` foreign key (`dataset_sid`) references `datasets` (`sid`) on delete cascade on update cascade,   constraint `fk_series_meas_sensor` foreign key (`sensor_sid`) references `sensors` (`sid`) on delete cascade on update cascade ) engine=innodb auto_increment=412908 default charset=utf8; 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -