Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 39B4F9FBA59 for ; Tue, 10 Jul 2007 06:16:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 10065-08 for ; Tue, 10 Jul 2007 06:16:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 360089FB8B4 for ; Tue, 10 Jul 2007 06:16:50 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l6A9GiaJ039837 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Jul 2007 03:16:47 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.14.1/8.14.1) with ESMTP id l6A9Gi1g049304; Tue, 10 Jul 2007 03:16:44 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.14.1/8.14.1/Submit) id l6A9Gi4R049303; Tue, 10 Jul 2007 03:16:44 -0600 (MDT) (envelope-from mfuhr) Date: Tue, 10 Jul 2007 03:16:43 -0600 From: Michael Fuhr To: Michele Petrazzo - Unipex srl Cc: pgsql-sql@postgresql.org Subject: Re: CIdr query qestion Message-ID: <20070710091643.GA48320@winnie.fuhr.org> References: <46933711.4030501@unipex.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46933711.4030501@unipex.it> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/45 X-Sequence-Number: 28780 On Tue, Jul 10, 2007 at 09:36:49AM +0200, Michele Petrazzo - Unipex srl wrote: > A question about cidr query. I'm tring to use the various cidr functions > to exclude a A sub class, but I don't understand how use it: > > SELECT count(ip_addr), ip_addr from wi_log_network where ip_addr != > network('10.10.0.0/16', 16) group by (ip_addr); > > it don't exclude the 10.10 ! Tried also the abbr or set_masklen keyword, > but the same. How do it? Please post the actual query you're running. The above fails with ERROR: function network("unknown", integer) does not exist Does the following help? CREATE TABLE test (id integer PRIMARY KEY, ip_addr inet NOT NULL); INSERT INTO test (id, ip_addr) VALUES (1, '10.2.3.4'); INSERT INTO test (id, ip_addr) VALUES (2, '10.10.5.6'); SELECT id, ip_addr, set_masklen(ip_addr, 16), network(set_masklen(ip_addr, 16)), network(set_masklen(ip_addr, 16)) = '10.10.0.0/16', '10.10.0.0/16'::cidr >> ip_addr, NOT '10.10.0.0/16'::cidr >> ip_addr FROM test; id | ip_addr | set_masklen | network | ?column? | ?column? | ?column? ----+-----------+--------------+--------------+----------+----------+---------- 1 | 10.2.3.4 | 10.2.3.4/16 | 10.2.0.0/16 | f | f | t 2 | 10.10.5.6 | 10.10.5.6/16 | 10.10.0.0/16 | t | t | f (2 rows) > P.s. Tried the >>, but it only include the values that I want to > exclude! (And I don't found how to do the opposite!) You can use NOT to negate a boolean expression; see above. -- Michael Fuhr