v.23.6Improvement

Allow casting IPv6 to IPv4 for CIDR ::ffff:0:0/96

Allow to cast IPv6 to IPv4 address for CIDR ::ffff:0:0/96 (IPv4-mapped addresses). #49759 (Yakov Olkhovskiy).
Adds support for casting IPv6 addresses to IPv4 when the IPv6 address belongs to the CIDR block ::ffff:0:0/96, which represents IPv4-mapped IPv6 addresses.

Why it matters

This feature enables seamless conversion from IPv6 to IPv4 addresses in cases where the IPv6 address is actually an IPv4-mapped address. It solves the problem of handling such specialized IPv6 addresses by allowing users to extract the embedded IPv4 part, improving compatibility and data processing across IP versions.

How to use it

Users can cast IPv6 addresses to IPv4 using the standard CAST syntax when the IPv6 address falls into the ::ffff:0:0/96 CIDR range. For example:

SELECT CAST(ipv6_column AS IPv4) FROM table
WHERE ipv6_column LIKE '::ffff:%';