我正在运行以下插入语句:
INSERT INTO list_subscribers (subscriberid, listid, emailaddress, domainname, format, confirmed, confirmcode, requestdate, requestip, confirmdate, confirmip, subscribedate, unsubscribed, unsubscribeconfirmed)
VALUES ('203404', 1, 'blah@gmail.com', '@gmail.com', 'h', 1, '1234', 1282196458, '', 1282196458, '', 1282196458, 0, 0 )
ON DUPLICATE KEY UPDATE emailaddress='blah@gmail.com', domainname = '@gmail.com', unsubscribed = 0, unsubscribeconfirmed = 0
我收到以下错误:
Error Code: 1062. Duplicate entry 'blah@gmail.com-1' for key 'subscribers_email_list_idx'
这是我的桌子的样子:
CREATE TABLE `list_subscribers` (
`subscriberid` int(11) NOT NULL AUTO_INCREMENT,
`listid` int(11) NOT NULL DEFAULT '0',
`emailaddress` varchar(200) DEFAULT NULL,
`domainname` varchar(100) DEFAULT NULL,
`format` char(1) DEFAULT NULL,
`confirmed` char(1) DEFAULT '0',
`confirmcode` varchar(32) DEFAULT NULL,
`requestdate` int(11) DEFAULT '0',
`requestip` varchar(20) DEFAULT NULL,
`confirmdate` int(11) DEFAULT '0',
`confirmip` varchar(20) DEFAULT NULL,
`subscribedate` int(11) DEFAULT '0',
`bounced` int(11) DEFAULT '0',
`unsubscribed` int(11) DEFAULT '0',
`unsubscribeconfirmed` char(1) DEFAULT '0',
`formid` int(11) DEFAULT '0',
PRIMARY KEY (`subscriberid`),
UNIQUE KEY `subscribers_email_list_idx` (`emailaddress`,`listid`),
KEY `list_subscribers_sub_list_idx` (`subscriberid`,`listid`),
KEY `subscribe_date_idx` (`subscribedate`),
KEY `list_subscribers_listid_idx` (`listid`),
KEY `confirmed_idx` (`confirmed`)
) ENGINE=InnoDB AUTO_INCREMENT=4687107 DEFAULT CHARSET=utf8
我认为这正是“ON DUPLICATE KEY UPDATE”语句的用途?为什么由于重复索引而中止查询?