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
ip
column so that seems good. So I scroll down to the first record which did not convert. It has a value of40036798809
which 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
UPDATE
query going in the ascending order of the primary keyid
) that theip
value for that record is10317637058914
which 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
ORDER
the table by theip
in HeidiSQL and then suddenly the highest value record for theip
column 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
BIGINT
has nothing to do with column range. HeidiSQL changes theip
column 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
ip
column is not checked for Unsigned that implies that theip
column 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 theUPDATE
query 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
UPDATE
query 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
UPDATE
query if theip
column 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
ORDER
in HeidiSQL that it is showing the effective highest value; is this best-guess accurate?