AWS Redshift中的INET_ATON等价物

时间:2014-10-06 21:45:43

标签: amazon-redshift maxmind

我无法在网上找到任何类似于AWS Redshift中的INET_ATON的文档。所以我想它还没有,但我想知道是否可以以某种方式解决方法。顺便说一下,我正在使用max_mind数据。

3 个答案:

答案 0 :(得分:2)

对于解决方法,您可以使用:

SELECT ipAddr, 
   SPLIT_PART(ipAddr, '.', 1)* 16777216::bigint +
   SPLIT_PART(ipAddr, '.', 2)* 65536::bigint +
   SPLIT_PART(ipAddr, '.', 3)* 256::bigint +
   SPLIT_PART(ipAddr, '.', 4)::bigint AS addressRange       
FROM <your_table) LIMIT 5

addressRange应与maxmind startIpNum&lt;匹配addressRange&lt; endIpNum。

答案 1 :(得分:0)

我最终在Python中创建了一个包装器(这是我正在使用的主要语言),它将IP字符串转换为数字然后使用它。

答案 2 :(得分:0)

我将国家/地区块和位置CSV加载到同名表中,并使用以下查询

加入
INSERT INTO dim.geoip_country
SELECT
        SPLIT_PART(first_ip, '.', 1) * 16777216::BIGINT
        + SPLIT_PART(first_ip, '.', 2) * 65536::BIGINT
        + SPLIT_PART(first_ip, '.', 3) * 256::BIGINT
        + SPLIT_PART(first_ip, '.', 4)::BIGINT AS ip_inf,
        SPLIT_PART(first_ip, '.', 1) * 16777216::BIGINT
        + SPLIT_PART(first_ip, '.', 2) * 65536::BIGINT
        + SPLIT_PART(first_ip, '.', 3) * 256::BIGINT
        + SPLIT_PART(first_ip, '.', 4)::BIGINT
        + POW(2, 32 - mask_bits)::BIGINT AS ip_sup,
        network,
        isocode2,
        name,
        continent_code,
        continent_name,
        is_anonymous_proxy,
        is_satellite_provider
FROM (
        SELECT
                b.network,
                SPLIT_PART(b.network, '/', 1) AS first_ip,
                SPLIT_PART(b.network, '/', 2)::INTEGER AS mask_bits,
                l.country_iso_code AS isocode2,
                l.country_name AS name,
                l.continent_code AS continent_code,
                l.continent_name AS continent_name,
                b.is_anonymous_proxy::BOOLEAN AS is_anonymous_proxy,
                b.is_satellite_provider::BOOLEAN AS is_satellite_provider
        FROM ext.geoip2_country_blocks_ipv4 b
        JOIN ext.geoip2_country_locations_en l
                ON b.geoname_id = l.geoname_id
)
相关问题