Created
June 7, 2024 20:30
-
-
Save rg443a/6ae8b251b16c0d1c1f17339ad2bb20b2 to your computer and use it in GitHub Desktop.
duckdb inet_aton function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION inet_aton(ip) AS ( | |
cast( | |
split_part(ip, '.', 1)::UINTEGER * 16777216 + | |
split_part(ip, '.', 2)::UTINYINT * 65536 + | |
split_part(ip, '.', 3)::UTINYINT * 256 + | |
split_part(ip, '.', 4)::UTINYINT as UINTEGER) | |
); | |
-- select inet_aton('255.255.255.252'); |
select #5,(#5>>24 & 255) || '.' || (#5>>16 & 255) || '.' || (#5>>8 & 255) || '.' || (#5 & 255)
ip
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CREATE OR REPLACE macro inet_ntoa (ip) as concat_ws('.', (ip >> 24) & 255 , (ip >> 16) & 255 , (ip >> 8) & 255 , ip & 255);