<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Error Inserting records into mariadb table using Python : 1366 (22007): Incorrect integer value: '%s' for column in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Error-Inserting-records-into-mariadb-table-using-Python-1366/m-p/296534#M218270</link>
    <description>&lt;P&gt;I am inserting records in maria db table from a file using python. Population column in the file is empty. I want it to go as empty value in table as well. Population column in table is set as integer and can accept null value. I am trying the below code -&lt;/P&gt;&lt;P&gt;Table Definition -&lt;BR /&gt;CREATE TABLE `local_db`.`table_x` (&lt;BR /&gt;`Unique_code` varchar(50) NOT NULL,&lt;BR /&gt;`city` varchar(200) DEFAULT NULL,&lt;BR /&gt;`state` varchar(50) DEFAULT NULL,&lt;BR /&gt;`population` bigint(20) DEFAULT NULL,&lt;BR /&gt;`Govt` varchar(50) DEFAULT NULL&lt;BR /&gt;) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;input_file = "input_file"&lt;BR /&gt;csv_data = csv.reader(open(input_file))&lt;BR /&gt;try:&lt;BR /&gt;connection = mysql.connector.connect(host='localhost',&lt;BR /&gt;database='local_db',&lt;BR /&gt;user='root',&lt;BR /&gt;password='root',&lt;BR /&gt;port = '3306')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;cursor = connection.cursor()&lt;BR /&gt;for row in csv_data:&lt;BR /&gt;cursor.execute("""&lt;BR /&gt;INSERT INTO table_x(Unique_code,city,state,population,Govt)&lt;BR /&gt;VALUES("%s", "%s", "%s","%s", "%s")&lt;BR /&gt;ON DUPLICATE KEY UPDATE city = VALUES(city),state = VALUES(state), \&lt;BR /&gt;population = VALUES(population),Govt = VALUES(Govt)""")&lt;BR /&gt;connection.commit()&lt;BR /&gt;print(cursor.rowcount, "Record inserted successfully into table_x")&lt;BR /&gt;cursor.close()&lt;/P&gt;&lt;P&gt;except mysql.connector.Error as error:&lt;BR /&gt;print("Failed to insert record into table_x table {}".format(error))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;finally:&lt;BR /&gt;if (connection.is_connected()):&lt;BR /&gt;connection.close()&lt;BR /&gt;print("MySQL connection is closed")&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;But I am getting below error -&lt;/P&gt;&lt;P&gt;Failed to insert record into table_x table 1366 (22007): Incorrect integer value: '%s' for column `local_db`.`table_x`.`population` at row 1&lt;BR /&gt;MySQL connection is closed&lt;/P&gt;&lt;P&gt;In other thread it was suggested to change&lt;BR /&gt;SET sql_mode = ""&lt;BR /&gt;But its not an option for me since I would be running it on organization server which I can not change for this only. Please suggest what code changes I can do here to handle this situation.&lt;/P&gt;</description>
    <pubDate>Mon, 25 May 2020 04:02:18 GMT</pubDate>
    <dc:creator>vikrant_kumar24</dc:creator>
    <dc:date>2020-05-25T04:02:18Z</dc:date>
    <item>
      <title>Error Inserting records into mariadb table using Python : 1366 (22007): Incorrect integer value: '%s' for column</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Error-Inserting-records-into-mariadb-table-using-Python-1366/m-p/296534#M218270</link>
      <description>&lt;P&gt;I am inserting records in maria db table from a file using python. Population column in the file is empty. I want it to go as empty value in table as well. Population column in table is set as integer and can accept null value. I am trying the below code -&lt;/P&gt;&lt;P&gt;Table Definition -&lt;BR /&gt;CREATE TABLE `local_db`.`table_x` (&lt;BR /&gt;`Unique_code` varchar(50) NOT NULL,&lt;BR /&gt;`city` varchar(200) DEFAULT NULL,&lt;BR /&gt;`state` varchar(50) DEFAULT NULL,&lt;BR /&gt;`population` bigint(20) DEFAULT NULL,&lt;BR /&gt;`Govt` varchar(50) DEFAULT NULL&lt;BR /&gt;) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;/P&gt;&lt;P&gt;```&lt;BR /&gt;input_file = "input_file"&lt;BR /&gt;csv_data = csv.reader(open(input_file))&lt;BR /&gt;try:&lt;BR /&gt;connection = mysql.connector.connect(host='localhost',&lt;BR /&gt;database='local_db',&lt;BR /&gt;user='root',&lt;BR /&gt;password='root',&lt;BR /&gt;port = '3306')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;cursor = connection.cursor()&lt;BR /&gt;for row in csv_data:&lt;BR /&gt;cursor.execute("""&lt;BR /&gt;INSERT INTO table_x(Unique_code,city,state,population,Govt)&lt;BR /&gt;VALUES("%s", "%s", "%s","%s", "%s")&lt;BR /&gt;ON DUPLICATE KEY UPDATE city = VALUES(city),state = VALUES(state), \&lt;BR /&gt;population = VALUES(population),Govt = VALUES(Govt)""")&lt;BR /&gt;connection.commit()&lt;BR /&gt;print(cursor.rowcount, "Record inserted successfully into table_x")&lt;BR /&gt;cursor.close()&lt;/P&gt;&lt;P&gt;except mysql.connector.Error as error:&lt;BR /&gt;print("Failed to insert record into table_x table {}".format(error))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;finally:&lt;BR /&gt;if (connection.is_connected()):&lt;BR /&gt;connection.close()&lt;BR /&gt;print("MySQL connection is closed")&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;But I am getting below error -&lt;/P&gt;&lt;P&gt;Failed to insert record into table_x table 1366 (22007): Incorrect integer value: '%s' for column `local_db`.`table_x`.`population` at row 1&lt;BR /&gt;MySQL connection is closed&lt;/P&gt;&lt;P&gt;In other thread it was suggested to change&lt;BR /&gt;SET sql_mode = ""&lt;BR /&gt;But its not an option for me since I would be running it on organization server which I can not change for this only. Please suggest what code changes I can do here to handle this situation.&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 04:02:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Error-Inserting-records-into-mariadb-table-using-Python-1366/m-p/296534#M218270</guid>
      <dc:creator>vikrant_kumar24</dc:creator>
      <dc:date>2020-05-25T04:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error Inserting records into mariadb table using Python : 1366 (22007): Incorrect integer value: '%s' for column</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Error-Inserting-records-into-mariadb-table-using-Python-1366/m-p/301428#M220662</link>
      <description>&lt;P&gt;This message is labeled NiFi, so I assume you have NiFi available?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In that case, look at finding the right processor for the job, something like ExecuteSQL may be a good starting point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;If your question is purely about how to make python and mariaDB interact, this may not be the best place to ask it.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 11:44:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Error-Inserting-records-into-mariadb-table-using-Python-1366/m-p/301428#M220662</guid>
      <dc:creator>DennisJaheruddi</dc:creator>
      <dc:date>2020-08-13T11:44:45Z</dc:date>
    </item>
  </channel>
</rss>

