Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 604D8B5DBFA for ; Sun, 21 Aug 2011 19:20:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 98063-03 for ; Sun, 21 Aug 2011 22:20:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id A8855B5DBBE for ; Sun, 21 Aug 2011 19:20:07 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QvGNB-0000ZQ-C5 for pgsql-sql@postgresql.org; Mon, 22 Aug 2011 00:20:05 +0200 Received: from 212.126.222.122 ([212.126.222.122]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 22 Aug 2011 00:20:05 +0200 Received: from hari.fuchs by 212.126.222.122 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 22 Aug 2011 00:20:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: exclusion constraint for ranges of IP Date: Mon, 22 Aug 2011 00:19:53 +0200 Lines: 16 Message-ID: <86ty9a5rw6.fsf@mgm.protecting.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 212.126.222.122 X-Archive: encrypt User-Agent: Gnus/5.110009 (No Gnus v0.9) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:xDEQWGTVjkqpL+JoldyDsdHMIjU= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.773 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_NUMERIC_HELO=1.164, RP_MATCHES_RCVD=-1.048, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201108/79 X-Sequence-Number: 35747 In article , Herouth Maoz 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, it is 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 to do 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))) );