Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZC941-0003zB-1u for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2015 16:16:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZC940-0004zV-HU for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Jul 2015 16:16:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZC93A-0004Im-IE for pgsql-bugs@postgresql.org; Mon, 06 Jul 2015 16:15:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZC937-0002rc-Nc for pgsql-bugs@postgresql.org; Mon, 06 Jul 2015 16:15:19 +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 t66GF9wq029011; Mon, 6 Jul 2015 12:15:09 -0400 From: Tom Lane To: stn@inbox.ru cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13488: Wrong netmask calculation In-reply-to: <20150706084821.1201.77035@wrigleys.postgresql.org> References: <20150706084821.1201.77035@wrigleys.postgresql.org> Comments: In-reply-to stn@inbox.ru message dated "Mon, 06 Jul 2015 08:48:21 -0000" Date: Mon, 06 Jul 2015 12:15:09 -0400 Message-ID: <29010.1436199309@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) 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 stn@inbox.ru writes: > database=# select inet(routedest), inet(routemask) from iprouteinterface > group by routedest, routemask order by routedest limit 3; > inet | inet > -----------+------------- > 0.0.0.0 | 0.0.0.0 > 10.1.0.0 | 255.255.0.0 > 10.10.0.0 | 255.255.0.0 > (3 rows) > database=# select inet(routedest), cidr(routemask) from iprouteinterface > group by routedest, routemask order by routedest limit 3; > inet | cidr > -----------+---------------- > 0.0.0.0 | 0.0.0.0/32 > 10.1.0.0 | 255.255.0.0/32 > 10.10.0.0 | 255.255.0.0/32 > (3 rows) > database=# select routedest, network(inet(routemask)) from iprouteinterface > group by routedest, routemask order by routedest limit 3; > routedest | network > -----------+---------------- > 0.0.0.0 | 0.0.0.0/32 > 10.1.0.0 | 255.255.0.0/32 > 10.10.0.0 | 255.255.0.0/32 > (3 rows) You did not say what you think is wrong here, but AFAICS all of these results are probably per the documentation (I say "probably" because, without having seen the input data, it's not entirely clear what calculations you're actually doing). I suspect what you are wishing for is a function that would take the inputs "10.1.0.0" and "255.255.0.0" and produce the CIDR value 10.1/16. That would be a reasonable thing to offer, perhaps, but it's not there now. In the meantime you could probably build it easily enough as a SQL function, at least for the set of mask values that actually occur in your data. 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