upsert - Mysql UPDATE ON DUPLICATE KEY only inserting -
to I'm trying to run a query in order to insert duplicates or update. I am using a unique index for duplicates, but I can not seem to do this work. It still adds new records, hoping for some fresh eyes can tell my problem. Thank you.
This is my schema
If the table does not exist then 'pricing_patching' (`custom 'varchar (6) default tap comment' customer code ',` Recipe 'Varchar (15) default faucet, `item' varchar (120) faucet 'item code' from dProduce,` unit_wector` double (12,4) default faucet, `case_cast` double (12,4) default null comment ' projected Projekted_rrjin float (12,3) default nULL Recommend 'projected margin', 'Projekted_mrjin' float (12, 3) default nULL a The Omtm 'projected price', `Prvritti` Tinint (1) level trends default tap Comment 1 = up, 0 = down,` Note 'varchar (255)' notes on the default tap Comment 'data,' Sptah_of` Date of 'Empty comment' This data, 'Accepted' tint (1) Default null comment 'Acceptance flag', 'Last_activated_prom' varchar (20) Identifier of the faucet comment to know where to save it at the end Was gone, 'saved', 'tap from time to time Save the Date Ippni '/ update' time saved '' I NT (11) does not command node "user created by ID) ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT = 'store pricing data; Optional table Add `Pricing_pitching` Add unique key 'CUSTO_RIPI__ ITEM_VIC_Off` (` CUSTO`, `method`,` item`, `week_off`), add key' custom '(` constan'a);
I'm checking this:
Pricing- Include in patching (recipe, item, unit_weight, casecast, cost_pre_lb, trend, note, week_off, Saved_atat, approved, accepted, last_activated_prom) value ('epiligra', 'epigraphy', 40.00,100.01,2.50,0, '', '2014-07-28', now (), 1, zero, 'purchase') Key update on Duplicate Unit_Vette = 40.00, Casecast = 100.01, cost_on_la_labie = 2.50, trend = 0, note = '', saved_at = now (), saved = 1, switches I have lost this case with the customer but I still have a problem with duplicate inserting. I have been doing this, I have been testing with 2 null values and no one still ... Is this my schema or is it an issue with my question?
A NULL
value is not considered "unique" first of unique index Column custno
, you are not providing a value for that column in INSERT, so the default value of the NULL is used as the value of that column.
Because of the net value is not considered unique, INSERT will not put a duplicate key exception.
Try it with a non-null value for the custno column.
In addition, you can use the special VALUES ()
function, in the updated part of the statement, to reference the value given in the INSERT.
Comments
Post a Comment