久久久久久久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 循環(huán)數(shù)組)
      <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 循環(huán)數(shù)組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

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

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

                我有一個如下的數(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|
                +---------------------------------------------
                

                我有一個主鍵 ZIP_CODE,我需要確保沒有重復(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ù)組來循環(huán)記錄,并對數(shù)據(jù)庫執(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()
                

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

                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 循環(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
                

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

                Thanks. Hope this will be of reference to others.

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

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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 個先前值來決定接下來的 N 個行)
                reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結(jié)果;條款?)
                Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項是忽略整個事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環(huán)數(shù)組)
                pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時發(fā)生錯誤 沒有合適的驅(qū)動程序)
                How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)
                  <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>

                          主站蜘蛛池模板: 欧美日韩精品一区二区 | 国产女人水真多18毛片18精品 | 爱爱短视频| www.亚洲视频 | 长河落日连续剧48集免费观看 | 欧美一区不卡 | 一本色道久久综合亚洲精品酒店 | 国产中文字幕在线观看 | 久久久久国产精品夜夜夜夜夜 | 一区在线视频 | 夜夜操天天操 | 极品新婚夜少妇真紧 | 97超碰资源站 | 麻豆一区二区三区 | 国产麻豆精品视频 | 蜜臀av性久久久久av蜜臀妖精 | 国产视频一区二区在线 | 免费视频a | 男女交配网站 | www.久久 | 永久免费视频 | 国产com | 精品一区视频 | 国产精品久久久久久久久借妻 | 日本精品久久 | 成人高潮片免费 | 在线网站免费观看18 | 国内久久精品 | 精品理论片 | 毛片中文字幕 | 欧美视频一区 | 久久狠狠干 | 四虎成人网 | 成人看片网站 | 伊人成人在线 | 黄色国产| 成人在线观看网站 | 黄色片一级片 | 亚洲h视频| 国产网站免费 | 国产精品激情 |