Re: inet increment w/ int8

Greg Stark <gsstark@mit.edu>

From: Greg Stark <gsstark@mit.edu>
To: Bruce Momjian <pgman@candle.pha.pa.us>
Cc: Greg Stark <gsstark@mit.edu>, pgsql-hackers@postgresql.org
Date: 2005-04-19T17:14:42Z
Lists: pgsql-hackers
Bruce Momjian <pgman@candle.pha.pa.us> writes:

> > Ie, 
> > 
> > 10.0.0.0/24   + 1 = 10.0.0.1/24
> > 10.0.0.255/24 + 1 => overflow
> > 
> > Or
> > 
> > 10.1/16 + 1      = 10.1.0.1/16
> > 10.1/16 + 16384  = 10.1.64.0/16
> > 10.1/16 + 65536  => overflow
> 
> So, do not overflow?  

You mean not doing modulus arithemtic? Yes. Overflow instead.

I see a use case for of generating addresses based on a sequence or some
primary key from the database.

Something like

CREATE SEQUENCE hosts_ip_seq MAXVALUE 65536;
ALTER TABLE hosts ALTER ip SET DEFAULT '10.0.0.0/16'::inet + nextval(hosts_ip_seq')

Using the primary key or some foreign key in the table would require a trigger
which would take too much work to cons up an example for.

-- 
greg