简体   繁体   中英

SQL replace into only the first two columns in a row

What I currently have is this:

PreparedStatement ps = getSQLConnection().prepareStatement(
    "REPLACE INTO " + table + " (uuid,name) VALUES(?,?)"
    );

ps.setString(1, uuid.toString());
ps.setString(2, name.toLowerCase());
ps.executeUpdate();

However it is not setting only index 1 and 2, but instead clears the other column values. How can I insert into a row with only the first 2 indexes, and leave the other values untouched?

The table is created with this statement:

"CREATE TABLE IF NOT EXISTS data (" +
"`uuid` varchar(36) NOT NULL," +
"`name` varchar," + 
"`owner` varchar," + 
"`tags` varchar," + 
"PRIMARY KEY (`uuid`));"

From the documentation :

REPLACE is a MySQL extension to the SQL standard. It either inserts, or deletes and inserts. For another MySQL extension to standard SQL—that either inserts or updates—see Section 13.2.5.3, “INSERT ... ON DUPLICATE KEY UPDATE Syntax”.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM