Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u9V77-002WV1-9m for pgsql-docs@arkaria.postgresql.org; Mon, 28 Apr 2025 20:30:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u9V65-0035kI-Fl for pgsql-docs@arkaria.postgresql.org; Mon, 28 Apr 2025 20:29:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u9V65-0035k1-8q for pgsql-docs@lists.postgresql.org; Mon, 28 Apr 2025 20:29:02 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u9V63-00044a-32 for pgsql-docs@lists.postgresql.org; Mon, 28 Apr 2025 20:29:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53SKSvPB898177; Mon, 28 Apr 2025 16:28:57 -0400 From: Tom Lane To: Nathan Long cc: pgsql-docs@lists.postgresql.org Subject: Re: `inet` docs suggestion and possible bug report In-reply-to: References: Comments: In-reply-to Nathan Long message dated "Mon, 28 Apr 2025 11:07:21 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <898175.1745872137.1@sss.pgh.pa.us> Date: Mon, 28 Apr 2025 16:28:57 -0400 Message-ID: <898176.1745872137@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Long writes: > At least in the case of `inet`, another reason is for accurate comparison. > IPv4 and IPv6 both have shorthand textual representations; eg `127.1` = > `127.1.0.0`. Text storage would consider these unequal. I'm not sure how much we want to press that point, because AFAICS the code we use does not have the same abbreviation rules you are expecting. Notably, it thinks '127.1' means 127.1.0.0. (We lifted this logic from BIND 20+ years ago, so while it might not entirely agree with practice elsewhere, it has a respectable pedigree and I'm hesitant to mess with it.) > A possible bug report: As of I expected `SELECT '127.1'::inet = > '127.0.0.1'::inet;` to return true, but as of 16.6 the cast on the > shorthand format fails, even though it handles the IPV6-mapped equivalent. That seems to be falling foul of this restriction in inet_net_pton_ipv4: /* Prefix length can default to /32 only if all four octets spec'd. */ if (bits == -1) { if (dst - odst == 4) bits = 32; else goto enoent; } although if we relaxed that restriction it'd still fail at the next bit, /* If prefix length overspecifies mantissa, life is bad. */ if ((bits / 8) > (dst - odst)) goto enoent; which is why '127.1/32'::inet also fails. Maybe somebody should take a look at current BIND and see if they redefined these rules. Per our git log, we've not attempted to sync this code with upstream since 2005. regards, tom lane