Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xgdev-0005CW-SY for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Oct 2014 17:55:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xgdev-0000yo-9O for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Oct 2014 17:55:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xgdet-0000wY-Il for pgsql-bugs@postgresql.org; Tue, 21 Oct 2014 17:55:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xgdep-0004jS-Nh for pgsql-bugs@postgresql.org; Tue, 21 Oct 2014 17:55:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s9LHtXfQ007718; Tue, 21 Oct 2014 13:55:33 -0400 From: Tom Lane To: michel@albert.lu cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11734: The "<<=" operator on "inet" values does not return the expected result. In-reply-to: <20141021114040.2674.45532@wrigleys.postgresql.org> References: <20141021114040.2674.45532@wrigleys.postgresql.org> Comments: In-reply-to michel@albert.lu message dated "Tue, 21 Oct 2014 11:40:40 -0000" Date: Tue, 21 Oct 2014 13:55:33 -0400 Message-ID: <7717.1413914133@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org michel@albert.lu writes: > The best way to explain this is with a quick example script: > CREATE TABLE inettest ( > value inet UNIQUE > ); > INSERT INTO inettest VALUES > ('1.2.1.0/24'), > ('1.2.1.1/24'), > ('1.2.1.2/24'), > ('1.2.2.0/24'), > ('1.2.3.0/24'), > ('1.2.3.1/24'), > ('1.2.3.2/24'), > ('1.2.3.3/24'), > ('1.2.3.4/24') > ; > SELECT * FROM inettest WHERE value <<= '1.2.3.1/24'::inet; > I would expect that the above select would only return *one* row. The one > with the host '1.2.3.1/24'. Instead, it returns *all* rows of the > '1.2.3.0/24' network. The PG documentation is pretty clear on this point: The operators <<, <<=, >>, >>=, and && test for subnet inclusion. They consider only the network parts of the two addresses (ignoring any host part) and determine whether one network is identical to or a subnet of the other. [ first para in "Network Address Functions and Operators" ] So <<= should return true for any two of the addresses you cite here. Personally I'd use CIDR, not INET, for anything I was thinking of as a network ID rather than a single host's ID. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs