Created
March 18, 2021 03:42
-
-
Save coderholic/426ac304b4639e0520afc6432d5cebcd to your computer and use it in GitHub Desktop.
IPinfo.io Snowflake UDFs
This file contains hidden or 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 secure function IPINFO.PUBLIC.to_join_key(ip text) returns integer as | |
\$\$ | |
AS_INTEGER(PARSE_IP(CONCAT(ip, '/16'), 'inet'):ipv4_range_start) | |
\$\$ | |
; | |
create or replace secure function IPINFO.PUBLIC.to_int(ip text) returns integer as | |
\$\$ | |
AS_INTEGER(PARSE_IP(ip, 'inet'):ipv4) | |
\$\$ | |
; | |
CREATE OR REPLACE SECURE FUNCTION IPINFO.PUBLIC.to_ip(ip integer) RETURNS text AS | |
\$\$ | |
(BITAND(BITSHIFTRIGHT(ip,24),255)::text || '.' | |
|| BITAND(BITSHIFTRIGHT(ip,16),255)::text || '.' | |
|| BITAND(BITSHIFTRIGHT(ip,8),255)::text || '.' | |
|| BITAND(ip,255)::text) | |
\$\$ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment