문제

I'm working on a rails app that has an IPv6 model. I'm storing the IPv6 address in 2 32-bit ints and a 64-bit int:

+-----------------------+---------------------+------+-----+---------+----------------+
| Field                 | Type                | Null | Key | Default | Extra          |
+-----------------------+---------------------+------+-----+---------+----------------+
| global_routing_prefix | int(11) unsigned    | YES  |     | NULL    |                | 
| subnet_identifier     | int(11) unsigned    | YES  |     | NULL    |                | 
| interface_identifier  | bigint(20) unsigned | YES  |     | NULL    |                | 

Unfortunately, when I go to find IPs in a range, MySQL does all arithmetic with signed bigints, so:

mysql> select 2 BETWEEN 0 AND 18446744073709551614;
+--------------------------------------+
| 2 BETWEEN 0 AND 18446744073709551614 |
+--------------------------------------+
|                                    0 | 
+--------------------------------------+

Is there a work around I can do, or do I need to split up by interface_identifier into 2 unsigned ints?

Thanks, Donald

도움이 되었습니까?

해결책

Doing it without using BETWEEN seems to work

mysql> select 0 <= 2 and 2 <= 18446744073709551614;
+--------------------------------------+
| 0 <= 2 and 2 <= 18446744073709551614 |
+--------------------------------------+
|                                    1 |
+--------------------------------------+

다른 팁

Ugly solution:

select 2 BETWEEN 0 AND CAST(18446744073709551614 AS DECIMAL);

People at MontyAB are working on native IPv6 column type for MariaDB/MySQL. If you can support them, we're likely to have this feature sooner. ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top