Re: Adding integers ( > 8 bytes) to an inet

From: Martin Gainty <mgainty(at)hotmail(dot)com>
To: <kristian(at)spritelink(dot)net>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Adding integers ( > 8 bytes) to an inet
Date: 2009-09-08 14:41:37
Message-ID: BLU142-W265F82B730470E5DE05255AEEA0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


Kristian

assuming the max size of 8 byte integer is
http://www.postgresql.org/docs/8.1/static/datatype.html
bigint8 byteslarge-range integer-9223372036854775808 to 9223372036854775807
i dont know if a IPV6 address
999999 999999 999999 999999 would fit into
9,223,372,036,854,775,807 boundary

i think you discovered the bug!

if you feel you have a solution try submitting a patch
http://wiki.postgresql.org/wiki/Submitting_a_Patch

please ping ping pgsql-hackers(at)postgresql(dot)org

Good Catch!
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> Date: Tue, 8 Sep 2009 15:58:25 +0200
> From: kristian(at)spritelink(dot)net
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] Adding integers ( > 8 bytes) to an inet
>
> 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(at)spritelink(dot)net
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

_________________________________________________________________
Get back to school stuff for them and cashback for you.
http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-09-08 15:06:36 Re: Adding integers ( > 8 bytes) to an inet
Previous Message Adrian Klaver 2009-09-08 14:33:09 Re: Order By Date Question

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2009-09-08 15:06:36 Re: Adding integers ( > 8 bytes) to an inet
Previous Message Kevin Grittner 2009-09-08 14:38:20 Re: Triggers on columns