db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Loucks <aar...@GardnerInc.com>
Subject insert / update on duplicate key question...
Date Thu, 17 Feb 2005 14:58:01 GMT
Is it possible to perform an update on a row with .doInsert() if the new
record would cause a duplicate value for the primary key? 

Basically I want to do something like this:

If you specify the ON DUPLICATE KEY UPDATE clause (new in MySQL 4.1.0), and
a row is inserted that would cause a duplicate value in a UNIQUE index or
PRIMARY KEY, an UPDATE of the old row is performed. For example, if column a
is declared as UNIQUE and contains the value 1, the following two statements
have identical effect:

mysql> INSERT INTO table (a,b,c) VALUES (1,2,3)
    -> ON DUPLICATE KEY UPDATE c=c+1;
mysql> UPDATE table SET c=c+1 WHERE a=1;

http://dev.mysql.com/doc/mysql/en/insert.html

- Aaron



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message