Re: inet increment w/ int8

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: inet increment w/ int8
Date: 2005-04-19 17:14:42
Message-ID: 877jiyk7st.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2005-04-19 17:32:25 Re: Problem with PITR recovery
Previous Message Bruce Momjian 2005-04-19 16:58:32 Re: Problem with PITR recovery