MySQL Forums
Forum List  »  General

any way to "ignore" a value in an INSERT/UPDATE query?
Posted by: michael cook
Date: July 11, 2013 09:57AM

I do a large number of INSERT ... ON DUPLICATE KEY UPDATE ... queries in 10k chunks (polling data on the net). The query is essentially:

INSERT INTO tbl (a,b,PKey) VALUES (...) ON DUPLICATE KEY UPDATE a=VALUES(a),b=VALUES(b)

This works great, but columns 'a' and 'b' come from separate data sources and aren't always updated at the same time; 'a' will change once a day, and 'b' will change once an hour. Right now I need to re-download 'a' each time I want to update the table. I'd like to make it more efficient by avoiding a re-download of 'a'.

I can check on a row-by-row basis as I generate the query if 'a' needs to change or not, but it's difficult to do on a "full query" basis - so - that leads to my question:

Is there a way I can have the UPDATE part of the query skip a particular value? so for example:
INSERT INTO tbl (a,b,PKey) VALUES (d,e,1),(f,g,2),(DEFAULT,i,3)... ON DUPLICATE KEY UPDATE a=VALUES(a),b=VALUES(b)

will set 'a' to its default value in row 3. Is there something similar but instead of set to a default value, skip that column entirely. ie:

INSERT INTO tbl (a,b,PKey) VALUES (d,e,1),(f,g,2),(SKIP,i,3)... ON DUPLICATE KEY UPDATE a=VALUES(a),b=VALUES(b)

that will cause col 'b' to be updated, but 'a' to be ignored?


Otherwise I will have to split the program into two pieces, which I'm trying to avoid:
INSERT INTO tbl (a,b,PKey) VALUES (...) ON DUPLICATE KEY UPDATE a=VALUES(a),b=VALUES(b)
and
INSERT INTO tbl (b,PKey) VALUES (...) ON DUPLICATE KEY UPDATE b=VALUES(b)

Anyway, if that's the only way I can make it work then so be it

Options: ReplyQuote


Subject
Written By
Posted
any way to "ignore" a value in an INSERT/UPDATE query?
July 11, 2013 09:57AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.