on-duplicate-key

Getting count of insert/update rows from ON DUPLICATE KEY UPDATE

感情迁移 提交于 2019-12-01 18:47:14
问题 I have a statement that tries to insert a record and if it already exists, it simply updates the record. INSERT INTO temptable (col1,col2,col3) VALUES (1,2,3) ON DUPLICATE KEY UPDATE col1=VALUES(col1), col2=VALUES(col2), col3=VALUES(col3); The full statement has multiple inserts and I'm looking to count number of INSERTs against the UPDATEs. Can I do this with MySQL variables, I've yet to find a way to do this after searching. 回答1: From Mysql Docs In the case of "INSERT ... ON DUPLICATE KEY

Doctrine: ON DUPLICATE KEY UPDATE

梦想的初衷 提交于 2019-11-30 23:20:05
问题 How can I write an INSERT doctrine query with option ON DUPLICATE KEY UPDATE ? 回答1: The problem is that this is a MySQL specific problem so it will not be directly covered by Doctrine. As a comment mentioned, you would need to write a RawSQL Query for this. This would be the easiest way. If you want it more sophisticated and truely DB independent, look into Events and it's possibilities. Before the actual query is executed, you can check for an existence and if it exists, act accordingly. An

Yii INSERT … ON DUPLICATE UPDATE

巧了我就是萌 提交于 2019-11-30 20:08:14
I am working on a Yii project. How can I use the ON DUPLICATE feature of MySQL ( http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html ) when doing a save() on a Yii model? My MySQL is as follows: CREATE TABLE `ck_space_calendar_cache` ( `space_id` int(11) NOT NULL, `day` date NOT NULL, `available` tinyint(1) unsigned NOT NULL DEFAULT '0', `price` decimal(12,2) DEFAULT NULL, `offer` varchar(45) DEFAULT NULL, `presale_date` date DEFAULT NULL, `presale_price` decimal(12,2) DEFAULT NULL, `value_x` int(11) DEFAULT NULL, `value_y` int(11) DEFAULT NULL, PRIMARY KEY (`space_id`,`day`), KEY

MySql - ON DUPLICATE KEY INSERT

冷暖自知 提交于 2019-11-30 19:52:01
I understand that there exists INSERT IGNORE and INSERT ... ON DUPLICATE KEY UPDATE . However, when there is a duplicate key, I'd like to do a INSERT to a temporary table to keep a record of the unique key that has been violated, so that I can output it to the user. Is there any way I can do a ON DUPLICATE INSERT ? If it helps, I'm trying to do a bulk insert. newfurniturey With ON DUPLICATE KEY UPDATE , you cannot insert into another table - nor is there an alternative function available. Two custom/alternative ways you can accomplish this: Using a stored procedure as outlined in the accepted

Yii INSERT … ON DUPLICATE UPDATE

坚强是说给别人听的谎言 提交于 2019-11-30 04:21:56
问题 I am working on a Yii project. How can I use the ON DUPLICATE feature of MySQL ( http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html ) when doing a save() on a Yii model? My MySQL is as follows: CREATE TABLE `ck_space_calendar_cache` ( `space_id` int(11) NOT NULL, `day` date NOT NULL, `available` tinyint(1) unsigned NOT NULL DEFAULT '0', `price` decimal(12,2) DEFAULT NULL, `offer` varchar(45) DEFAULT NULL, `presale_date` date DEFAULT NULL, `presale_price` decimal(12,2) DEFAULT

MySql - ON DUPLICATE KEY INSERT

ε祈祈猫儿з 提交于 2019-11-30 04:17:11
问题 I understand that there exists INSERT IGNORE and INSERT ... ON DUPLICATE KEY UPDATE . However, when there is a duplicate key, I'd like to do a INSERT to a temporary table to keep a record of the unique key that has been violated, so that I can output it to the user. Is there any way I can do a ON DUPLICATE INSERT ? If it helps, I'm trying to do a bulk insert. 回答1: With ON DUPLICATE KEY UPDATE , you cannot insert into another table - nor is there an alternative function available. Two custom

PDO prepared statements for INSERT and ON DUPLICATE KEY UPDATE with named placeholders

六月ゝ 毕业季﹏ 提交于 2019-11-27 16:23:46
问题 I'd like to switch PDO INSERT and UPDATE prepared statements to INSERT and ON DUPLICATE KEY UPDATE since I think it'll be a lot more efficient than what I'm currently doing, but I'm having trouble figuring out the correct syntax to use with named placeholders and bindParam. I found several similar question on SO, but I'm new to PDO and couldn't successfully adapt the code for my criteria. This is what I've tried, but it doesn't work (it doesn't insert or update): try { $stmt = $conn->prepare(

Is there a way to use ON DUPLICATE KEY to Update all that I wanted to insert?

喜欢而已 提交于 2019-11-27 11:00:06
I know that you can use ON DUPLICATE KEY UPDATE to update a certain value if there is a record for that key already, I can do this: INSERT INTO `tableName` (`a`,`b`,`c`) VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE `a`=1, `b`=2, `c`=3 But how can I do this without having to write out the columns and values twice? Unfortunately not. You can get half-way there by not having to repeat the value: INSERT INTO `tableName` (`a`,`b`,`c`) VALUES (1,2,3) ON DUPLICATE KEY UPDATE `a`=VALUES(`a`), `b`=VALUES(`b`), `c`=VALUES(`c`); But you still have to list the columns. use REPLACE INTO The meaning of REPLACE

Too many auto increments with ON DUPLICATE KEY UPDATE

我的未来我决定 提交于 2019-11-27 07:52:19
I have a basic table with columns: id (primary with AI) name (unique) etc If the unique column doesn't exist, INSERT the row, otherwise UPDATE the row.... INSERT INTO pages (name, etc) VALUES 'bob', 'randomness' ON DUPLICATE KEY UPDATE name = VALUES(name), etc = VALUES(etc) The problem is that if it performs an UPDATE, the auto_increment value on the id column goes up. So if a whole bunch of UPDATES are performed, the id auto_increment goes through the roof. Apparently it was a bug: http://bugs.mysql.com/bug.php?id=28781 ...but I'm using InnoDB on mySQL 5.5.8 on shared hosting. Other people

Is there a way to use ON DUPLICATE KEY to Update all that I wanted to insert?

柔情痞子 提交于 2019-11-26 17:58:48
问题 I know that you can use ON DUPLICATE KEY UPDATE to update a certain value if there is a record for that key already, I can do this: INSERT INTO `tableName` (`a`,`b`,`c`) VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE `a`=1, `b`=2, `c`=3 But how can I do this without having to write out the columns and values twice? 回答1: Unfortunately not. You can get half-way there by not having to repeat the value: INSERT INTO `tableName` (`a`,`b`,`c`) VALUES (1,2,3) ON DUPLICATE KEY UPDATE `a`=VALUES(`a`), `b`