I have the following MySQL database table:
CREATE TABLE `example` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`ip` BIGINT(11) NOT NULL,
`ipv6` VARBINARY(16) NOT NULL
PRIMARY KEY (`id`)
);
My goal is simply to copy/convert the existing IPv4 IP addresses in to IPv6 format in the new ipv6 column. So I run the following query which worked just fine in all my test cases:
UPDATE example SET ipv6 = INET6_ATON(INET_NTOA(ip));
This should be simple right? No... After processing 1,083 records MariaDB returns the following error:
Column 'ipv6' cannot be null.
I'm thinking odd so I decide to start verifying the data:
- There are 1279 records in this table.
- All records contain a value for the
ipcolumn so that seems good. So I scroll down to the first record which did not convert. It has a value of40036798809which is 11 numbers so that should match up withINT(11)right? - However the second row that was not processed (keeping in mind that MySQL naturally executed the
UPDATEquery going in the ascending order of the primary keyid) that theipvalue for that record is10317637058914which is 14 numbers long which is not supposed to be possible in anINT(11)field, correct? - I see some other integers that are clearly exceeding the integer length so I decide to
ORDERthe table by theipin HeidiSQL and then suddenly the highest value record for theipcolumn is1202623438. That is ten numbers in length. phpMyAdmin also shows the larger number however I have switched to HeidiSQL since I find it's GUI is superior for my local development. - After some research it appears that the length of the datatype for
BIGINThas nothing to do with column range. HeidiSQL changes theipcolumn values by simply changing theORDER!
- My next step after continued reading was to check whether the column is signed or unsigned. As HeidiSQL shows that the
ipcolumn is not checked for Unsigned that implies that theipcolumn is signed and therefore it's maximum value is (all commas added only for visualization, actual values are purely numeric) 2,147,483,647 while the value that would not parse during theUPDATEquery is 40,036,798,809. - Earlier research suggested that if a number in the column is larger than what is allowed (not sure why that would even be allowed?) then it would be treated as the maximum allowed value (I imagine in this case 2,147,483,647); is this true?
The Question(s)
- In summation: why won't the
UPDATEquery parse the entire table? - Which depends on: what is the problem with MySQL and/or HeidiSQL with storing values?
- Will MariaDB / MySQL allow the storage of numbers larger than what the table structure allows?
- How is is the value 40,036,798,809 (again, without commas) being treated during the
UPDATEquery if theipcolumn type isBIGINT(11)? - What would be the effective value stored for the highest valid IPv4 IP address (255.255.255.255)?
- I presume when I
ORDERin HeidiSQL that it is showing the effective highest value; is this best-guess accurate?
