I am creating a table using mysql.connector
in Python. When I insert an integer value into my table, SQL converts it to some other integer value. Here is my code:
cursor.execute("CREATE TABLE cleaned_data (myid VARCHAR(255), mynum INTEGER(255))")
cursor.execute("INSERT INTO cleaned_data(myid, mynum) VALUES(%s,%s)", ('mytext',25683838382092010098988))
rows = cursor.execute('select * from cleaned_data;')
for row in cursor:
print(row)
Here is the output of the printed row:
('mytext', 2147483647)
Any idea what is going on? I want my table to store my integer number, even if it is huge.
CodePudding user response:
INTEGER(255)
doesn't do what you think.
Max value of an integer is 2147483647 (signed) or 4294967295 (unsigned).
See this answer for more detail What is the size of column of int(11) in mysql in bytes?
CodePudding user response:
To store numbers up to 65 digits, you can use the decimal type. For instance, for integers with 25 digits, use decimal(25,0)