{"id":26042,"date":"2024-11-24T08:33:08","date_gmt":"2024-11-24T00:33:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26042\/"},"modified":"2024-11-24T08:33:08","modified_gmt":"2024-11-24T00:33:08","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8-pymysql-%e6%89%a7%e8%a1%8c%e5%90%ab-on-duplicate-key-update-%e8%af%ad%e5%8f%a5%e7%9a%84-executemany-%e5%87%ba%e7%8e%b0%e7%bc%96%e7%a8%8b%e9%94%99-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26042\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4f7f\u7528 pymysql \u6267\u884c\u542b `on duplicate key update` \u8bed\u53e5\u7684 `executemany` \u51fa\u73b0\u7f16\u7a0b\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173078126931022.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u4f7f\u7528 pymysql \u6267\u884c\u542b `on duplicate key update` \u8bed\u53e5\u7684 `executemany` \u51fa\u73b0\u7f16\u7a0b\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u4f7f\u7528 pymysql \u6267\u884c\u542b `on duplicate key update` \u8bed\u53e5\u7684 `executemany` \u51fa\u73b0\u7f16\u7a0b\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u793a\u4f8b\u4e2d\uff0con duplicate key update &#8230; \u8bed\u53e5\u7684\u5b58\u5728\u4e0d\u4f1a\u5bfc\u81f4<strong>py<\/strong>\u4e2d\u51fa\u73b0\u7684\u7f16\u7a0b\u9519\u8bef\u3002\u95ee\u9898\u51fa\u5728\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a<\/p>\n<pre>cursor.executemany('''insert into myfund(fcode,fname,nav,accnav,updatetime)\nvalues(%(fcode)s,%(fname)s,%(nav)s,%(accnav)s,%(updatetime)s)\non duplicate key update `updatetime`= %(updatetime)s,nav= %(nav)s,accnav= %(accnav)s ''',\nresult)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>pymysql \u65e0\u6cd5\u6b63\u786e\u8f6c\u4e49 sql \u67e5\u8be2\u4e2d\u7684\u5360\u4f4d\u7b26 (%(fcode)s \u7b49)\u3002\u56e0\u6b64\uff0c\u5b83\u4f1a\u5728\u6267\u884c\u67e5\u8be2\u65f6\u5f15\u53d1\u7f16\u7a0b\u9519\u8bef\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u590d\u540e\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>cursor.executemany('''insert into myfund(fcode,fname,NAV,ACCNAV,updatetime)\nvalues(%s,%s,%s,%s,%s)\non duplicate key update `updatetime`= %s,NAV= %s,ACCNAV= %s ''',\nresult)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c%s \u5360\u4f4d\u7b26\u5df2\u66ff\u6362\u4e3a\u5e38\u89c4\u5360\u4f4d\u7b26\uff0cpymysql \u53ef\u4ee5\u6b63\u786e\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u8f6c\u4e49\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 py \u6267\u884c\u542b `on duplicate key update` \u8bed\u53e5\u7684 `executemany` \u51fa\u73b0\u7f16\u7a0b\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u793a\u4f8b\u4e2d\uff0con duplicate key update &#8230; \u8bed\u53e5\u7684\u5b58\u5728\u4e0d\u4f1a\u5bfc\u81f4py\u4e2d\u51fa\u73b0\u7684\u7f16\u7a0b\u9519\u8bef\u3002\u95ee\u9898\u51fa\u5728\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a cursor.executemany(&#8221;&#8217;insert into myfund(fcode,fname,nav,accnav,updatetime) values(%(fcode)s,%(fname)s,%(nav)s,%(accnav)s,%(updatetime)s) on duplicate key update `updatetime`= %(updatetime)s,nav= %(nav)s,accnav= %(accnav)s &#8221;&#8217;, result) \u767b\u5f55\u540e\u590d\u5236 pymysql \u65e0\u6cd5\u6b63\u786e\u8f6c\u4e49 sql \u67e5\u8be2\u4e2d\u7684\u5360\u4f4d\u7b26 (%(fcode)s \u7b49)\u3002\u56e0\u6b64\uff0c\u5b83\u4f1a\u5728\u6267\u884c\u67e5\u8be2\u65f6\u5f15\u53d1\u7f16\u7a0b\u9519\u8bef\u3002 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u590d\u540e\u7684\u4ee3\u7801\uff1a cursor.executemany(&#8221;&#8217;insert into myfund(fcode,fname,NAV,ACCNAV,updatetime) values(%s,%s,%s,%s,%s) on duplicate key update `updatetime`= %s,NAV= %s,ACCNAV= %s &#8221;&#8217;, result) \u767b\u5f55\u540e\u590d\u5236 \u8bf7\u6ce8\u610f\uff0c%s \u5360\u4f4d\u7b26\u5df2\u66ff\u6362\u4e3a\u5e38\u89c4\u5360\u4f4d\u7b26\uff0cpymysql \u53ef\u4ee5\u6b63\u786e\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u8f6c\u4e49\u3002 \u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 py \u6267\u884c\u542b `on duplicate key update` \u8bed\u53e5\u7684 `executemany` [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26042","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26042"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26042\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}