久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='nC7jj'><tr id='nC7jj'><dt id='nC7jj'><q id='nC7jj'><span id='nC7jj'><b id='nC7jj'><form id='nC7jj'><ins id='nC7jj'></ins><ul id='nC7jj'></ul><sub id='nC7jj'></sub></form><legend id='nC7jj'></legend><bdo id='nC7jj'><pre id='nC7jj'><center id='nC7jj'></center></pre></bdo></b><th id='nC7jj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nC7jj'><tfoot id='nC7jj'></tfoot><dl id='nC7jj'><fieldset id='nC7jj'></fieldset></dl></div>

      1. <small id='nC7jj'></small><noframes id='nC7jj'>

        <tfoot id='nC7jj'></tfoot>
          <bdo id='nC7jj'></bdo><ul id='nC7jj'></ul>
      2. <legend id='nC7jj'><style id='nC7jj'><dir id='nC7jj'><q id='nC7jj'></q></dir></style></legend>

        使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用

        Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用 for 循環(huán)數(shù)組)

          <tfoot id='5Os1G'></tfoot>
        • <legend id='5Os1G'><style id='5Os1G'><dir id='5Os1G'><q id='5Os1G'></q></dir></style></legend>

              <small id='5Os1G'></small><noframes id='5Os1G'>

                  <tbody id='5Os1G'></tbody>
                • <bdo id='5Os1G'></bdo><ul id='5Os1G'></ul>

                • <i id='5Os1G'><tr id='5Os1G'><dt id='5Os1G'><q id='5Os1G'><span id='5Os1G'><b id='5Os1G'><form id='5Os1G'><ins id='5Os1G'></ins><ul id='5Os1G'></ul><sub id='5Os1G'></sub></form><legend id='5Os1G'></legend><bdo id='5Os1G'><pre id='5Os1G'><center id='5Os1G'></center></pre></bdo></b><th id='5Os1G'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5Os1G'><tfoot id='5Os1G'></tfoot><dl id='5Os1G'><fieldset id='5Os1G'></fieldset></dl></div>
                  本文介紹了使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用 for 循環(huán)數(shù)組的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在使用 pyspark 框架更新 mysql 數(shù)據(jù)庫(kù),并在 AWS Glue 服務(wù)上運(yùn)行.

                  I am working on updating a mysql database using pyspark framework, and running on AWS Glue services.

                  我有一個(gè)如下的數(shù)據(jù)框:

                  I have a dataframe as follows:

                  df2= sqlContext.createDataFrame([("xxx1","81A01","TERR NAME 55","NY"),("xxx2","81A01","TERR NAME 55","NY"),("x103","81A01","TERR NAME 01","NJ")], ["zip_code","territory_code","territory_name","state"])
                  
                  # Print out information about this data
                  df2.show()
                  +--------+--------------+--------------+-----+
                  |zip_code|territory_code|territory_name|state|
                  +--------+--------------+--------------+-----+
                  |    xxx1|         81A01|  TERR NAME 55|   NY|
                  |    xxx2|         81A01|  TERR NAME 55|   NY|
                  |    x103|         81A01|  TERR NAME 01|   NJ|
                  +---------------------------------------------
                  

                  我有一個(gè)主鍵 ZIP_CODE,我需要確保沒(méi)有重復(fù)鍵或主鍵異常,因此我使用 INSERT INTO .... ON DUPLICATE KEYS.

                  I have a primary key ZIP_CODE, and I need to ensure, there is no duplicate keys, or primary key exceptions, and hence am using INSERT INTO .... ON DUPLICATE KEYS.

                  而且由于我有不止一行要插入/更新,所以我在 python 中使用了數(shù)組來(lái)循環(huán)記錄,并對(duì)數(shù)據(jù)庫(kù)執(zhí)行 INSERT.代碼如下:

                  And since I have more than one rows to insert/update, I have used for array in python to loop through the records, and perform INSERT into database. The code is as follows:

                  sarry = df2.collect()
                  for r in sarry:
                       db = MySQLdb.connect("xxxx.rds.amazonaws.com", "username", "password", 
                        "databasename")
                       cursor = db.cursor()
                       insertQry=INSERT INTO ZIP_TERR(zip_code, territory_code, territory_name, 
                       state) VALUES(r.zip_code, r.territory_code, r.territory_name, r.state) ON 
                       DUPLICATE KEY UPDATE territory_name = VALUES(territory_name), state = 
                       VALUES(state);"
                       n=cursor.execute(insertQry)
                       db.commit()
                       db.close()
                  

                  在運(yùn)行上述插入查詢(xún)函數(shù)時(shí),我收到以下錯(cuò)誤消息,無(wú)法獲得有關(guān)錯(cuò)誤的任何線(xiàn)索.請(qǐng)幫忙.

                  When running the above insert query function, I am getting the following error message, couldn't get any clue on the error. Please help.

                  Traceback (most recent call last):
                    File "/tmp/zeppelin_pyspark-2291407229037300959.py", line 367, in <module>
                      raise Exception(traceback.format_exc())
                  Exception: Traceback (most recent call last):
                    File "/tmp/zeppelin_pyspark-2291407229037300959.py", line 360, in <module>
                      exec(code, _zcUserQueryNameSpace)
                    File "<stdin>", line 8, in <module>
                    File "/usr/local/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
                      result = self._query(query)
                    File "/usr/local/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
                      conn.query(q)
                    File "/usr/local/lib/python2.7/site-packages/pymysql/connections.py", line 893, in query
                      self._affected_rows = self._read_query_result(unbuffered=unbuffered)
                    File "/usr/local/lib/python2.7/site-packages/pymysql/connections.py", line 1103, in _read_query_result
                      result.read()
                    File "/usr/local/lib/python2.7/site-packages/pymysql/connections.py", line 1396, in read
                      first_packet = self.connection._read_packet()
                    File "/usr/local/lib/python2.7/site-packages/pymysql/connections.py", line 1059, in _read_packet
                      packet.check_error()
                    File "/usr/local/lib/python2.7/site-packages/pymysql/connections.py", line 384, in check_error
                      err.raise_mysql_exception(self._data)
                    File "/usr/local/lib/python2.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
                      raise errorclass(errno, errval)
                  InternalError: (1054, u"Unknown column 'r.zip_code' in 'field list'")
                  

                  如果我只是嘗試打印一行的值,則會(huì)按如下方式打印值:

                  If i simply try to print the values for one row, am getting the values printed as follows:

                  print('zip_code_new: ', r.zip_code, r.territory_code, r.territory_name, r.state)
                  
                  zip_code_new:  xxx1 81A01 TERR NAME 55 NY
                  

                  謝謝.我正在研究 AWS Glue/Pyspark,所以我需要使用原生 Python 庫(kù).

                  Thanks. I am working on AWS Glue/Pyspark, so I need to use native python libraries.

                  推薦答案

                  以下插入查詢(xún)有效,帶有 for 循環(huán).

                  The following insert query works, with a for loop.

                  insertQry="INSERT INTO ZIP_TERR(zip_code, territory_code, territory_name, state) VALUES(%s, %s, %s, %s) ON DUPLICATE KEY UPDATE territory_name = %s, state = %s;
                  
                  n=cursor.execute(insertQry, (r.zip_code, r.territory_code, r.territory_name, r.state, r.territory_name, r.state))
                  print (" CURSOR status :", n)
                  

                  結(jié)果輸出:

                  CURSOR status : 2
                  

                  謝謝.希望對(duì)大家有所參考.

                  Thanks. Hope this will be of reference to others.

                  這篇關(guān)于使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用 for 循環(huán)數(shù)組的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個(gè)先前值來(lái)決定接下來(lái)的 N 個(gè)行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達(dá)式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項(xiàng)是忽略整個(gè)事務(wù)還是只是有問(wèn)題的行?) - IT屋-程序員軟件開(kāi)發(fā)技
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時(shí)發(fā)生錯(cuò)誤 沒(méi)有合適的驅(qū)動(dòng)程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫(kù)表作為 Spark 數(shù)據(jù)幀讀取?)
                  In Apache Spark 2.0.0, is it possible to fetch a query from an external database (rather than grab the whole table)?(在 Apache Spark 2.0.0 中,是否可以從外部數(shù)據(jù)庫(kù)獲取查詢(xún)(而不是獲取整個(gè)表)?) - IT屋-程序員軟件開(kāi)
                  <legend id='c6v5M'><style id='c6v5M'><dir id='c6v5M'><q id='c6v5M'></q></dir></style></legend>

                        <small id='c6v5M'></small><noframes id='c6v5M'>

                          <tbody id='c6v5M'></tbody>

                        1. <i id='c6v5M'><tr id='c6v5M'><dt id='c6v5M'><q id='c6v5M'><span id='c6v5M'><b id='c6v5M'><form id='c6v5M'><ins id='c6v5M'></ins><ul id='c6v5M'></ul><sub id='c6v5M'></sub></form><legend id='c6v5M'></legend><bdo id='c6v5M'><pre id='c6v5M'><center id='c6v5M'></center></pre></bdo></b><th id='c6v5M'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='c6v5M'><tfoot id='c6v5M'></tfoot><dl id='c6v5M'><fieldset id='c6v5M'></fieldset></dl></div>
                          • <bdo id='c6v5M'></bdo><ul id='c6v5M'></ul>
                            <tfoot id='c6v5M'></tfoot>

                          • 主站蜘蛛池模板: 黄色片免费看 | 成人在线精品 | 日中文字幕在线 | 男女羞羞在线观看 | 国产精品96久久久久久 | 视频二区在线观看 | 91精品成人久久 | 久久精彩视频 | 亚州激情 | 奇米av | 国偷自产av一区二区三区 | 欧美精品欧美精品系列 | 亚洲一区国产精品 | 999精彩视频| 国产精品欧美一区二区三区 | 超碰成人免费观看 | 色av一区 | 中文字幕在线播放第一页 | japanhd成人 | 天堂在线www| 在线观看国产wwwa级羞羞视频 | 在线中文视频 | 一级片av | 一区二区三区国产好的精 | 久久精品国产亚洲夜色av网站 | 国产成人99久久亚洲综合精品 | 精品一区免费 | 久久精品国产一区二区三区 | 毛片视频网址 | h视频网站在线观看 | 日本不卡一区二区 | 精品国产伦一区二区三区观看体验 | 亚洲一区免费在线 | 欧美日韩精品久久久免费观看 | 国产一区二区三区四区五区加勒比 | 欧美一级片 | 亚洲精品9999 | 亚洲中午字幕 | 国产精品一区二区三区99 | 欧美日日 | 日韩精品一区二区三区在线观看 |