Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon redshift AWS红移中的INET_ATON等效物_Amazon Redshift_Maxmind - Fatal编程技术网

Amazon redshift AWS红移中的INET_ATON等效物

Amazon redshift AWS红移中的INET_ATON等效物,amazon-redshift,maxmind,Amazon Redshift,Maxmind,我在网上找不到任何文档,无论AWS Redshift中是否有类似INET_ATON的内容。所以我想它还没有出现,但我想知道是否有一个解决办法,在某种程度上。顺便说一句,我使用的是max_mind数据。我最终用Python(我使用的主要语言)创建了一个包装器,将IP字符串转换成一个数字,然后使用它 对于解决方案,您可以使用: SELECT ipAddr, SPLIT_PART(ipAddr, '.', 1)* 16777216::bigint + SPLIT_PART(ipAddr,

我在网上找不到任何文档,无论AWS Redshift中是否有类似INET_ATON的内容。所以我想它还没有出现,但我想知道是否有一个解决办法,在某种程度上。顺便说一句,我使用的是max_mind数据。

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

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

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
选择ipAddr,
拆分部分(ipAddr,“.”,1)*16777216::bigint+
拆分部分(ipAddr,“.”,2)*65536::bigint+
拆分部分(ipAddr,“.”,3)*256::bigint+
拆分部分(ipAddr,“.”,4)::作为地址范围的bigint

从中,我将国家块和位置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
)