Re: exclusion constraint for ranges of IP - Mailing list pgsql-sql

From Harald Fuchs
Subject Re: exclusion constraint for ranges of IP
Date
Msg-id 86ty9a5rw6.fsf@mgm.protecting.net
Whole thread Raw
In response to exclusion constraint for ranges of IP  (Herouth Maoz <herouth@unicell.co.il>)
Responses Re: exclusion constraint for ranges of IP  (Herouth Maoz <herouth@unicell.co.il>)
List pgsql-sql
In article <CAF36091-203E-4C10-AA53-7D9087114D35@unicell.co.il>,
Herouth Maoz <herouth@unicell.co.il> writes:

> Hi,
> I'm designing a new database. One of the table contains allowed IP ranges for a customer (Fields: customer_id,
from_ip,to_ip) which is intended to check - if  an incoming connection's originating IP number falls within the range,
itis identified as a particular customer.
 

> Naturally, I'd like to have constraints on the table that prevent entering of ip ranges that overlap. Is there a way
todo that with exclusion constraints? Or do I have to define a new type for this?
 

This "new type" already exists: ip4r, which can be found in pgfoundry.
With it you can do

CREATE TABLE mytbl ( iprange ip4r NOT NULL, ..., CONSTRAINT range_check CHECK ((NOT overlap(iprange)))
);



pgsql-sql by date:

Previous
From: Herouth Maoz
Date:
Subject: exclusion constraint for ranges of IP
Next
From: Herouth Maoz
Date:
Subject: Re: exclusion constraint for ranges of IP