Thread: inet subtraction fails with IPv6?

inet subtraction fails with IPv6?

From
Jon Nelson
Date:
Example (using one of google's IPv6 addrs):

jnelson=# select inet '0::0' - inet '2001:4860:4006:800::1011';
ERROR:  result is out of range
jnelson=#


--
Jon

Re: inet subtraction fails with IPv6?

From
Robert Haas
Date:
On Tue, Jan 31, 2012 at 10:38 AM, Jon Nelson <jnelson+pgsql@jamponi.net> wr=
ote:
> Example (using one of google's IPv6 addrs):
>
> jnelson=3D# select inet '0::0' - inet '2001:4860:4006:800::1011';
> ERROR: =A0result is out of range
> jnelson=3D#

What were you expecting to get?  There's no such thing as a negative IP add=
ress.

--=20
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: inet subtraction fails with IPv6?

From
Jon Nelson
Date:
On Tue, Jan 31, 2012 at 2:03 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Tue, Jan 31, 2012 at 10:38 AM, Jon Nelson <jnelson+pgsql@jamponi.net> =
wrote:
>> Example (using one of google's IPv6 addrs):
>>
>> jnelson=3D# select inet '0::0' - inet '2001:4860:4006:800::1011';
>> ERROR: =C2=A0result is out of range
>> jnelson=3D#
>
> What were you expecting to get? =C2=A0There's no such thing as a negative=
 IP address.

True, but it works for IPv4:

jnelson=3D# select inet '255.255.255.255' - inet '0/0';
  ?column?
------------
 4294967295
(1 row)

Time: 0.417 ms
jnelson=3D# select inet '0/0' - inet '255.255.255.255';
  ?column?
-------------
 -4294967295
(1 row)

Time: 0.166 ms
jnelson=3D#


If it makes you happy, reverse the arguments and try it again.

--=20
Jon

Re: inet subtraction fails with IPv6?

From
Tom Lane
Date:
Jon Nelson <jnelson+pgsql@jamponi.net> writes:
> On Tue, Jan 31, 2012 at 2:03 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>> What were you expecting to get? There's no such thing as a negative IP address.

> True, but it works for IPv4:

> jnelson=# select inet '255.255.255.255' - inet '0/0';
>   ?column?
> ------------
>  4294967295
> (1 row)

The inet minus inet operator is defined to yield bigint, so it only
copes for addresses within 2^63 of each other.  Short of inventing an
integer type at least 129 bits wide, the only way we could fix this is
to make the operator return numeric instead, which doesn't really seem
like an improvement for typical use-cases.  I'm fairly sure this was
debated when the operator was added, and we thought it was an acceptable
limitation; though maybe with IPv6 finally starting to see real usage
it's going to seem less so.

            regards, tom lane