Re: inet increment w/ int8 - Mailing list pgsql-hackers

From Greg Stark
Subject Re: inet increment w/ int8
Date
Msg-id 877jiyk7st.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: inet increment w/ int8  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: inet increment w/ int8  ("Ilya A. Kovalenko" <shadow@oganer.net>)
List 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



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Problem with PITR recovery
Next
From: Jeff Davis
Date:
Subject: Re: Problem with PITR recovery