Document toolboxDocument toolbox

Geolocated Level 1 Subdivision with MaxMind GeoIP2 (mm2subdivision1)

Description

Uses MaxMind GeoIP2 services to return the level 1 geographic subdivision associated with an IPv4 or IPv6 address. 

The level 1 subdivision is a string of up to three characters containing the region-portion of the ISO 3166-2 code for the first level region associated with the IP address. Some countries have two levels of subdivisions, in which case this is the least specific. For example, in the United Kingdom, this will be a country like "England", not a county like "Devon". However, for US locations, the level 1 subdivision will be the state.

Learn more in the MaxMind GeoIP2 developer documentation.

How does it work in the search window?

This operation only requires one argument:

Argument

Data type

Argument

Data type

Ip (v4 or v6) mandatory

ip, ip6

The data type of the new column is string.

Example

We want to get the level 1 geographic subdivisions associated with the IP addresses in our clientIpAddress column, so we click Create column and select the Geolocated Level 1 Subdivision with MaxMind GeoIP2 operation. Select clientIpAddress as the argument and assign a name to the new column - let's call it level1SubRegion.

The result is a column of string data type containing the ISO 3166-2 code for the subdivision.

How does it work in LINQ?

Use the operator select... as...  and add the operation syntax to create the new column. 

  • mm2subdivision1(ip)

  • mm2subdivision1(ip6)

Example

Copy the following LINQ script and try the above example on the demo.ecommerce.data table. 

from demo.ecommerce.data select mm2subdivision1(clientIpAddress) as level1SubRegion

In order to have context for the geographic subdivision, it's important to know in which country each IP address is located. In this example, we use the Geolocated Country with MaxMind GeoIP2 (mm2country) operation to provide this context.

from demo.ecommerce.data select mm2country(clientIpAddress) as country, mm2subdivision1(clientIpAddress) as level1SubRegion