Search Postgresql Archives

Adding integers ( > 8 bytes) to an inet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello!

I'm having some trouble with the inet data type and its
operators. Right now I'm relying on operations such as
 
kll=# SELECT '10.0.0.0/24'::inet + (2^(32-24))::integer;
  ?column?   
-------------
 10.0.1.0/24
(1 row)
 
to get the "next" available /24. This works all fine and dandy
for IPv4 since I'll never go beyond what an integer has to offer.
Expanding my application to IPv6 will on the other hand cause me
some trouble since 2^128 won't fit in an integer and not in a
bigint either. I tried numeric;
 
kll=> SELECT '2000::/48'::inet + (2^(128-96))::numeric(100);
ERROR: operator does NOT exist: inet + numeric
LINE 1: SELECT '2000::/48'::inet + (2^(128-96))::numeric(100);
                                 ^
HINT: No operator matches the given name AND argument type(s). You might need TO ADD explicit type casts.


And poking in pg_operator / pg_type seems to confirm this:

nils=# SELECT (SELECT typname FROM pg_type WHERE typelem=oprleft), oprname, (SELECT typname FROM pg_type WHERE typelem=oprright) FROM pg_operator WHERE oprleft=(SELECT typelem FROM pg_type WHERE typname='_inet') AND oprname='+';
 ?column? | oprname | ?column? 
----------+---------+----------
 _inet    | +       | _int8
(1 row)

I could hack together some kluge to loop through, but it all
becomes quite ugly after a while and I would rather see some way
to add a numeric.
 
Am I doing it the wrong way? Bug?
What to do?

Kind regards,
   Kristian.

-- 
Kristian Larsson                                        KLL-RIPE
+46 704 264511			              kll@xxxxxxxxxxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux