Re: Adding integers ( > 8 bytes) to an inet - Mailing list pgsql-general

From Kristian Larsson
Subject Re: Adding integers ( > 8 bytes) to an inet
Date
Msg-id 20090908155800.GN47859@spritelink.se
Whole thread Raw
In response to Re: Adding integers ( > 8 bytes) to an inet  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Adding integers ( > 8 bytes) to an inet
Re: Adding integers ( > 8 bytes) to an inet
List pgsql-general
On Tue, Sep 08, 2009 at 11:37:02AM -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre@commandprompt.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@spritelink.net

pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: Order By Date Question
Next
From: Kristian Larsson
Date:
Subject: Re: Adding integers ( > 8 bytes) to an inet