Pretty new to SQL.
I have a table (client_info
) in PostgreSQL (v11.1) that includes the following columns:
+----------+------------------+
| clientip | clientip_country |
+----------+------------------+
| 8.8.8.8 | null |
| 1.1.1.1 | null |
| 4.4.4.4 | null |
+----------+------------------+
I'm trying to create a function/script that will lookup the country ISO code for each clientip
using a local install of the MaxMind GeoLite2 database and then update the corresponding clientip_country
with the result to give:
+----------+------------------+
| clientip | clientip_country |
+----------+------------------+
| 8.8.8.8 | US |
| 1.1.1.1 | AU |
| 4.4.4.4 | US |
+----------+------------------+
What's the best way to go about achieving this?
For example I'm able to retrieve the country ISO code of an IP using the following bash command:
$ mmdblookup -f /usr/share/GeoIP/GeoLite2-Country.mmdb -i 1.1.1.1 country iso_code | sed -e '/^$/d' -e 's/.*"\(.*\)".*/\1/'
AU
What direction should I be looking to? An SQL command that queries the GeoLite2 DB? Or a bash script that queries the Postgres DB and updates the clientip_country
column with the results?