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

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

    <tfoot id='kPjoJ'></tfoot>
      <legend id='kPjoJ'><style id='kPjoJ'><dir id='kPjoJ'><q id='kPjoJ'></q></dir></style></legend>

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

      • <bdo id='kPjoJ'></bdo><ul id='kPjoJ'></ul>
    1. 使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用

      Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
      <legend id='38RpI'><style id='38RpI'><dir id='38RpI'><q id='38RpI'></q></dir></style></legend>

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

          <small id='38RpI'></small><noframes id='38RpI'>

          <tfoot id='38RpI'></tfoot>

            • <bdo id='38RpI'></bdo><ul id='38RpI'></ul>
              • 本文介紹了使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 pyspark 框架更新 mysql 數據庫,并在 AWS Glue 服務上運行.

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

                我有一個如下的數據框:

                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|
                +---------------------------------------------
                

                我有一個主鍵 ZIP_CODE,我需要確保沒有重復鍵或主鍵異常,因此我使用 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 中使用了數組來循環記錄,并對數據庫執行 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()
                

                在運行上述插入查詢函數時,我收到以下錯誤消息,無法獲得有關錯誤的任何線索.請幫忙.

                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'")
                

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

                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 庫.

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

                推薦答案

                以下插入查詢有效,帶有 for 循環.

                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)
                

                結果輸出:

                CURSOR status : 2
                

                謝謝.希望對大家有所參考.

                Thanks. Hope this will be of reference to others.

                這篇關于使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                  <tbody id='NhzvA'></tbody>

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

                <tfoot id='NhzvA'></tfoot>
                  <bdo id='NhzvA'></bdo><ul id='NhzvA'></ul>

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

                      <legend id='NhzvA'><style id='NhzvA'><dir id='NhzvA'><q id='NhzvA'></q></dir></style></legend>

                          主站蜘蛛池模板: 男女视频91| 午夜影院 | 国产高清精品一区二区三区 | 色婷婷精品 | 亚洲精品久久久久中文字幕欢迎你 | 欧美成年网站 | 日韩欧美高清dvd碟片 | 亚洲视频精品在线 | 老司机精品福利视频 | 国产精品三级 | 免费小视频在线观看 | 日韩精品一区在线观看 | 亚洲午夜三级 | 99久久精品视频免费 | 福利网址| 欧美日韩国产精品一区 | 欧美国产一区二区三区 | 亚洲二区在线 | www.伊人.com | 污污的网站在线观看 | 一区二区三区网站 | 九色视频网站 | 精品视频在线一区 | 亚洲精品一级 | 国产欧美一区二区三区久久 | 91麻豆精品国产91久久久久久 | 国产精品综合 | 成人精品视频 | 日韩中文字幕免费 | 欧美日韩亚洲一区 | 成人久久18免费网站 | 国产一区不卡 | 一区二区视频 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲免费视频一区 | 亚洲日本乱码在线观看 | 在线视频一区二区 | 成年网站在线观看 | 亚洲九九色 | 色噜噜色综合 | 99影视|