2014-10-06 70 views
1

我無法在Web上找到任何文檔,在AWS Redshift中是否存在類似INET_ATON的文檔。所以我想它還沒有,但我想知道是否可以有某種解決方法。順便說一句,我正在使用max_mind數據。INET_ATON等效於AWS Redshift

回答

0

我最終創建了一個Python包裝器(這是我使用的主要語言),它將IP字符串轉換爲數字,然後使用它。

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 < addressRange < endIpNum。

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 
) 
加盟