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 16:04:34
Message-ID: 20090908160433.GO47859@spritelink.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Sep 08, 2009 at 05:58:00PM +0200, Kristian Larsson wrote:
> 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?

Answering to my own post *documenting for generations to come*,
guess I could do :

kll=# SELECT broadcast('2000::/32') + 1;
?column?
-------------
2000:1::/32

Not very fugly.. that'll do in the meantime :)

-K

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2009-09-08 16:11:02 Re: Adding integers ( > 8 bytes) to an inet
Previous Message Kristian Larsson 2009-09-08 15:58:01 Re: Adding integers ( > 8 bytes) to an inet

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Gould 2009-09-08 16:09:35 Disable and enable of table and column constraints
Previous Message Pavel Stehule 2009-09-08 16:03:23 Re: Time-based Releases WAS: 8.5 release timetable, again