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

From: Kristian Larsson <kristian(at)spritelink(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Adding integers ( > 8 bytes) to an inet
Date: 2009-09-08 15:58:01
Message-ID: 20090908155800.GN47859@spritelink.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Sep 08, 2009 at 11:37:02AM -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> > I'd say this is just a missing feature.
>
> I think the whole thing is a bit of a crock; adding integers to inet
> addresses doesn't make a lot of sense logically. Perhaps what is
> really wanted is functions on CIDR net identifiers, for instance
>
> first_address('10/8') = 10.0.0.0
> last_address('10/8') = 10.255.255.255
> prior_address('10/8') = 9.255.255.255
> next_address('10/8') = 11.0.0.0
>
> which would have obvious extensions to IPv6 without having to bring
> numerics into the picture.
>
> What are the actual applications for adding integers to inet addresses?
> The one Kristian mentions seems to be covered by next_address(), but
> are there others?

My application is a IP address planning tool. The user can make a
request "give me an address from address-pool X" and a stored
procedure will go and find the next available address, it does so
by looping through a prefix, incrementing with the requested
prefix-length for each loop and returning a prefix if it does not
yet exist in the table.

first_address() is basically just host(network('10/8)) while
last_address() is host(broadcast('10/8')), so I see little use
for those. next_address() however, as shown above, seems to fill
my requirements.

For me, as a network engineer, adding an integer to a inet feels
quite natural. Inet is just another representation of a integer
anyway... so I'd really not have a problem with having either a
int16 or being able to add numerics to inets :)

Btw, anyone have a workaround for my issue?

Kind regards,
Kristian.

--
Kristian Larsson KLL-RIPE
+46 704 264511 kll(at)spritelink(dot)net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kristian Larsson 2009-09-08 16:04:34 Re: Adding integers ( > 8 bytes) to an inet
Previous Message David Fetter 2009-09-08 15:53:58 Re: Order By Date Question

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2009-09-08 16:03:23 Re: Time-based Releases WAS: 8.5 release timetable, again
Previous Message Tom Lane 2009-09-08 15:50:01 Re: Patch: update Bonjour support to the newer non-deprecated API