How to get country hierarchy

I’m trying to construct a full list of iso-3166-1 country codes into a hierarchy. The primary use would be to ensure that we are applying GDPR correctly to all countries and their territories, but it would be interesting for the rest of the world as well. I’ve been unable to find a full (concise) listing anywhere on the internet. I’ve got osm loaded into postgis and I’m able to find some hierarchies based on and intersection of admin_level 3 with admin_level 2 with iso-3166-1 codes defined (e.g. US->PR, FR->PF, etc). However there are many admin_level 2 countries that don’t seem to have any tags that refer to the top level country. For example, if I’m reading wikipedia correctly, Ascension should be 3 levels deep:

Is there any way to construct the full hierarchy of iso-3166-1 country codes from osm loaded in postgis?


What about trying to get your aim via ???

YOu can also create a query to find all countries of a certain level, and the wanted code should be included there for each, or no?