Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZDvxC-0006vA-0H for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Jul 2015 14:40:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZDvxA-0001fv-4u for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Jul 2015 14:40:32 +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 1ZDvwW-0000vg-BF for pgsql-bugs@postgresql.org; Sat, 11 Jul 2015 14:39:52 +0000 Received: from pro-open.de ([87.106.136.39] helo=www.pro-open.de) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZDvwS-0004oK-N4 for pgsql-bugs@postgresql.org; Sat, 11 Jul 2015 14:39:51 +0000 Received: from [192.168.0.22] (ip-95-222-240-82.hsi15.unitymediagroup.de [95.222.240.82]) by www.pro-open.de (Postfix) with ESMTP id D3DDB100A091 for ; Sat, 11 Jul 2015 16:39:45 +0200 (CEST) Message-ID: <55A12AC6.9000107@pro-open.de> Date: Sat, 11 Jul 2015 16:40:06 +0200 From: "Gunnar \"Nick\" Bluth" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #13488: Wrong netmask calculation References: <20150706084821.1201.77035@wrigleys.postgresql.org> <29010.1436199309@sss.pgh.pa.us> In-Reply-To: <29010.1436199309@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------090507040509000901090103" X-Pg-Spam-Score: -2.5 (--) 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 This is a multi-part message in MIME format. --------------090507040509000901090103 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 06.07.2015 um 18:15 schrieb Tom Lane: > 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. That "function" is an operator: || Though, inet() only accepts the short netmask format ("/0" and "/16" in your example), so you'll need to convert that first, like in e.g.: http://postgresql.nabble.com/dotted-quad-netmask-conversion-td3295932.ht ml I'm dealing with data from those DBMS' that don't offer proper datatypes quite often, and I'm pretty sure what you're looking for is something like (using the functions in that mailthread, at $WORK I have something quite similar in place): SELECT proper.net, network(proper.net), netmask(proper.net) -- [, etc. pp.] FROM ( SELECT inet( routedest || '/' || netmask_bits(inet_to_longip(routemask)) ) AS net FROM iprouteinterface ) proper Best regards, - -- Gunnar "Nick" Bluth RHCE/SCLA Mobil +49 172 8853339 Email: gunnar.bluth@pro-open.de _____________________________________________________________ In 1984 mainstream users were choosing VMS over UNIX. Ten years later they are choosing Windows over UNIX. What part of that message aren't you getting? - Tom Payne -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (MingW32) iQEcBAEBAgAGBQJVoSrGAAoJEBAQrmsyiTOM7xMIAL4Ndd5Rxi4rodoMoytqDnCY Zh9t9xB9fHBZknXT/wluiLlCj4U/t1ld0MKOLIlRsuRSe6vDxudbKGgQz5yBLBJq BjZ2RPlhUn62J3EY8Jj5YPPg3s3xZhSEGgLN/g7loihLkfLglTcY1nQKwLUX8ifg FdK70xGxZj6QXqBvnGHDldJZL28RdUAXcdzJygd1iMPQCHoBtgK7VUGNXq9ZYRGY js2duWYpXqHaESMRVw2JJJFW/jSEvmYV9WMITxZJe/+wRS6rF+VG5FL1SkKofkdZ abhoYcKRU1GA7/hCwu28jyT3PreL4ZnqrDJWiArDmD0uKHEpZ2oySkjGk0ENt1I= =Y2zl -----END PGP SIGNATURE----- --------------090507040509000901090103 Content-Type: application/pgp-keys; name="0x3289338C.asc" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0x3289338C.asc" -----BEGIN PGP PUBLIC KEY BLOCK-----=0A= Version: GnuPG v2.0.22 (MingW32)=0A= =0A= mQENBFOuo7ABCADU3rFM4gBv4l/Xjfry27pfdYgvWrcR1RA/vLfOgjqivSbMQEHH=0A= bTWprJRjB2EbzmTS+faSa/V+mH/jIKBytCc5+hprBd/m5if3/v2PKA7+MHsy1H9T=0A= 7FqTKRccNl7RIcKFOaonIbY4qMyH6cFafZOgqaGlc3ibfX7PiCL+mdl1mPoyWeVR=0A= sKoddSobI40noE+se/FrnKZRDRWqqx7zvTRRK9vKUVDFM+Y3Kg3EDL3Qmt3MocM7=0A= FtBZDaeyFZiKdf7bNaWM977aGwiA1gQQp+/TmB1qqSyOTzbPhxfr7G9vWdbVS2ph=0A= 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0A= dNKU3CyA+3T4FuKGL7RPrICJa+VdCvwMk8dzLqF0UgdfVHtCnUQoQmNnDD7gODw/=0A= GTIKpWw+iEE2/EANAONXj7EC+VsW895/C5aQEZx++cSonrHFSSIUp1OGJoVlmFnJ=0A= MFCTTElmayTcmfOwGHrn97Et5YePMOsyqWZas+URuJveoTdGhDToOIufECGb3WJa=0A= J8rFL+ni3NKoiZhZMYVQ+XC8f64Mi5kXlfsylVu6kgCoFqnq7FTpwqOiRml4APeX=0A= GBC6uZW6fUGNDQ=3D=3D=0A= =3D//tm=0A= -----END PGP PUBLIC KEY BLOCK-----=0A= --------------090507040509000901090103 Content-Type: application/octet-stream; name="0x3289338C.asc.sig" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="0x3289338C.asc.sig" iQEcBAABAgAGBQJVoSrGAAoJEBAQrmsyiTOMZfcIAKOsUiSMjEFFpBO/MkU8 4RwonN0ND8Z4/TXdv2aWfWSMT0OFENdeiEdqA+37TK14nRZUnvEv/R3ClOXr kY2OgG449C93ui6aIFxFTwZ6EO+mNyMxYo4kLQlz5ODf/5mf+RnSHsActtxg awO2aH8jPiSJy6IGBy5HYOKfHzEKbE1pWtSWFESh5o52DzQuPGPkYXTii6oI CZ9MAgEPaqBsGbHQKxTfGuluDgCS9uyWbVIHTJD3MtOuJZ9DSxlR3jQghwOf ZmZZCURW/ksqBqDRAlMsDN0jXMwMINJjQaT3wp317Ka5We1+/eMZt9+s/zyY tc0VEB5iNuW1z9zGmbqIJNw= --------------090507040509000901090103 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------090507040509000901090103--