我需要帮助将一个postgres函数迁移到snowflake函数。
目前,我有以下函数,它接收一个ip_address并返回ip_address的起始范围。
...
begin
if (p_ip_address is not null) then
return p_ip_address::inet - '0.0.0.0';
else
return null;
end if;
end
...
我知道我们有 PARSE_IP 在snowflake中给出了JSON文件,但我只需要其中的一段(ipv4_range_start)
例如
Input = 192.168.242.188
Output = 3232297472
如果你只想要一部分信息,请选择它。
select parse_ip('127.0.0.0/24','INET') as a
,a:ipv4_range_end;
给予:
A A:IPV4_RANGE_END
{ "family": 4, "host": "127.0.0.0", "ip_fields": [ 2130706432, 0, 0, 0 ], "ip_type": "inet", "ipv4": 2130706432, "ipv4_range_end": 2130706687, "ipv4_range_start": 2130706432, "netmask_prefix_length": 24, "snowflake$type": "ip_address" } 2130706687