Skip to content

United Nations

UN SDG, UNESCO, World Heritage, World Population Prospects, UNHCR and WHO data as tidy tables

Connector software
Free and open source
Service credentials
Optional
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/un/index.md to help me query United Nations with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Life expectancy at birth in India by sex, 2015-2021

Example output · captured
Connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT year, sex, value
FROM un.health.data('WHOSIS_000001')
WHERE country_iso3 = 'IND' AND year BETWEEN 2015 AND 2021
ORDER BY year, sex
Result · first 5 rows
year sex value
2015 SEX_BTSX 69.1
2015 SEX_FMLE 70.5
2015 SEX_MLE 67.8
2016 SEX_BTSX 69.5
2016 SEX_FMLE 70.9

Quick start

Choose where to run United Nations, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'un' AS un (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-un-worker'
);

3. Add service credentials (optional)

Most tables need no key; only the UN Population Division API needs a token. Replace the placeholders with your service settings.

un_population credentials

Bearer token for the UN DESA Population Division Data Portal API (population.data).

Get these credentials →
secret.sql
CREATE SECRET un_population (
    TYPE un_population,
    token '<UN_POPULATION_TOKEN>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT year, sex, value
FROM un.health.data('WHOSIS_000001')
WHERE country_iso3 = 'IND' AND year BETWEEN 2015 AND 2021
ORDER BY year, sex
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'un' AS un (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-un-worker'
);

Overview

Curated United Nations statistics as tidy country-year tables: SDG indicators, UNESCO education data, the World Heritage List, World Population Prospects, UNHCR refugee figures and WHO health indicators.

ATTACH options

base_url
Where requests go. Empty (default): each organisation's public API. An http(s) URL: a mirror or proxy serving <base_url>/<schema>/<api path>. A local directory: recorded responses (see test/fixtures), for offline use and tests.VARCHAR
user_agent
User-Agent sent upstream (default 'vgi-un/0.1 (+https://query.farm)').VARCHAR

Catalog

Everything un exposes once attached — read straight from the worker's released build.

un 7 schemas
health 3 tables · 2 functions

WHO Global Health Observatory: about 3,000 health indicators and their observations by country, WHO region, year and sex.

Schema examples (6)
Examples (6)

Life expectancy at birth in India by sex, 2015-2021

SELECT year, sex, value
FROM un.health.data('WHOSIS_000001')
WHERE country_iso3 = 'IND' AND year BETWEEN 2015 AND 2021
ORDER BY year, sex;
Result · first 5 rows
year sex value
2015 SEX_BTSX 69.1
2015 SEX_FMLE 70.5
2015 SEX_MLE 67.8
2016 SEX_BTSX 69.5
2016 SEX_FMLE 70.9

Life expectancy in 2019 in three South Asian countries, with M49 names

SELECT d.country_iso3, m.country_or_area, d.value
FROM un.health.data('WHOSIS_000001') d
JOIN un.main.m49_countries m ON m.iso_alpha3 = d.country_iso3
WHERE d.country_iso3 IN ('BGD', 'IND', 'PAK') AND d.year = 2019 AND d.sex = 'SEX_BTSX'
ORDER BY d.value DESC;

Decode the SEX dimension

SELECT code, title FROM un.health.dimension_values('SEX') ORDER BY code;

Find the life expectancy indicators

SELECT indicator_code, name
FROM un.health.indicators
WHERE name ILIKE '%life expectancy%'
ORDER BY indicator_code;
2 more examples

Number of countries in each WHO region

SELECT who_region, count(*) AS countries
FROM un.health.countries
GROUP BY who_region
ORDER BY who_region;

Dimensions about age

SELECT dimension, title
FROM un.health.dimensions
WHERE title ILIKE '%age%'
ORDER BY dimension;
Tables
countries 1 example4 cols

Countries in the WHO Global Health Observatory with their WHO region

Columns
country_iso3not null VARCHAR
ISO 3166-1 alpha-3 code as used in SpatialDim.
name VARCHAR
Country name.
who_region_code VARCHAR
WHO region code: AFR, AMR, SEAR, EUR, EMR, WPR.
who_region VARCHAR
WHO region name, e.g. 'South-East Asia'.
ConstraintsPRIMARY KEY (country_iso3)
Example

Number of countries in each WHO region

SELECT who_region, count(*) AS countries
FROM un.health.countries
GROUP BY who_region
ORDER BY who_region;
Link
dimensions 1 example2 cols

GHO dimension types (SEX, AGEGROUP, ...) that observations are broken down by

Columns
dimensionnot null VARCHAR
Dimension code, e.g. 'SEX', 'AGEGROUP', 'COUNTRY'.
title VARCHAR
Dimension title.
ConstraintsPRIMARY KEY (dimension)
Example

Dimensions about age

SELECT dimension, title
FROM un.health.dimensions
WHERE title ILIKE '%age%'
ORDER BY dimension;
Link
indicators 1 example2 cols

The 3,000+ WHO Global Health Observatory indicators with their codes and names

Columns
indicator_codenot null VARCHAR
GHO indicator code, e.g. 'WHOSIS_000001'.
name VARCHAR
Indicator name, e.g. 'Life expectancy at birth (years)'.
ConstraintsPRIMARY KEY (indicator_code)
Example

Find the life expectancy indicators

SELECT indicator_code, name
FROM un.health.indicators
WHERE name ILIKE '%life expectancy%'
ORDER BY indicator_code;
Link
Table functions
data (indicator VARCHAR) 2 examples

WHO Global Health Observatory observations of one indicator, by country or region, year and sex

Arguments
indicator VARCHAR
GHO indicator code from health.indicators, e.g. 'WHOSIS_000001'.
Returns columns
indicator_code VARCHAR
GHO indicator code.
country_iso3 VARCHAR
ISO alpha-3 code when the spatial dimension is a country, else NULL.
spatial_dim_type VARCHAR
COUNTRY, REGION, WORLDBANKINCOMEGROUP, GLOBAL, ...
spatial_dim VARCHAR
Area code: ISO alpha-3 for countries, e.g. 'SEAR' for a region.
parent_location_code VARCHAR
WHO region code of the country, e.g. 'SEAR'.
parent_location VARCHAR
WHO region name.
year INTEGER
Year, when the time dimension is a year (NULL otherwise).
time_dim_type VARCHAR
YEAR, or another period type.
period VARCHAR
The period as published, e.g. '2019' or '2015-2019'.
period_begin DATE
First day of the period.
period_end DATE
Last day of the period.
sex VARCHAR
Sex code (SEX_BTSX, SEX_FMLE, SEX_MLE) when one of the dimensions is SEX.
dim1_type VARCHAR
First disaggregation dimension type, e.g. 'SEX'.
dim1 VARCHAR
First disaggregation code, e.g. 'SEX_MLE'.
dim2_type VARCHAR
Second disaggregation dimension type.
dim2 VARCHAR
Second disaggregation code.
dim3_type VARCHAR
Third disaggregation dimension type.
dim3 VARCHAR
Third disaggregation code.
data_source VARCHAR
Data source dimension code, when published.
value DOUBLE
Numeric value (NumericValue).
value_text VARCHAR
Display value as published, e.g. '70.1 [68.8-71.5]'.
low DOUBLE
Lower uncertainty bound.
high DOUBLE
Upper uncertainty bound.
comments VARCHAR
Published comment or footnote.
updated_at TIMESTAMP WITH TIME ZONE
When WHO last updated the observation.
Examples (2)

Life expectancy at birth in India by sex, 2015-2021

SELECT year, sex, value
FROM un.health.data('WHOSIS_000001')
WHERE country_iso3 = 'IND' AND year BETWEEN 2015 AND 2021
ORDER BY year, sex;
Result · first 5 rows
year sex value
2015 SEX_BTSX 69.1
2015 SEX_FMLE 70.5
2015 SEX_MLE 67.8
2016 SEX_BTSX 69.5
2016 SEX_FMLE 70.9

Life expectancy in 2019 in three South Asian countries, with M49 names

SELECT d.country_iso3, m.country_or_area, d.value
FROM un.health.data('WHOSIS_000001') d
JOIN un.main.m49_countries m ON m.iso_alpha3 = d.country_iso3
WHERE d.country_iso3 IN ('BGD', 'IND', 'PAK') AND d.year = 2019 AND d.sex = 'SEX_BTSX'
ORDER BY d.value DESC;
Link
dimension_values (dimension VARCHAR) 1 example

The codes and titles of one GHO dimension, e.g. SEX -> SEX_MLE 'Male'

Arguments
dimension VARCHAR
Dimension code from health.dimensions, e.g. 'SEX' or 'AGEGROUP'.
Returns columns
dimension VARCHAR
The dimension asked for.
code VARCHAR
Value code, e.g. 'SEX_MLE'.
title VARCHAR
Value title, e.g. 'Male'.
parent_dimension VARCHAR
Parent dimension code, when hierarchical.
parent_code VARCHAR
Parent value code.
parent_title VARCHAR
Parent value title.
Example

Decode the SEX dimension

SELECT code, title FROM un.health.dimension_values('SEX') ORDER BY code;
Link
heritage 1 function

The UNESCO World Heritage List: inscribed cultural, natural and mixed properties.

Schema examples (2)
Examples (2)

Sites on the List of World Heritage in Danger, by category

SELECT category, count(*) AS sites
FROM un.heritage.sites()
WHERE in_danger
GROUP BY category
ORDER BY category;

World Heritage sites in Syria with their inscription year and criteria

SELECT name, year_inscribed, criteria
FROM un.heritage.sites(country := 'SYR')
ORDER BY year_inscribed, name;
Table functions
sites (country := VARCHAR) 2 examples

UNESCO World Heritage List sites with category, criteria, inscription year, danger status and location

Named arguments
country := VARCHAR
Only sites of this State Party, ISO alpha-3 ('FRA'); default '' = all countries. · default ""
Returns columns
site_id VARCHAR
World Heritage id number, e.g. '20' (also in the whc.unesco.org URL).
name VARCHAR
Site name (English).
category VARCHAR
Cultural, Natural or Mixed.
criteria VARCHAR[]
Selection criteria as roman numerals, e.g. ['i', 'iii', 'iv'].
year_inscribed INTEGER
Year the site was first inscribed.
inscription_years INTEGER[]
Year of inscription and of each extension.
in_danger BOOLEAN
True when the site is on the List of World Heritage in Danger.
danger_history VARCHAR
Danger-list history as published, e.g. 'Y 2013' (years on the list).
date_end DATE
Date the site was removed from the List (delisted sites), else NULL.
area_ha DOUBLE
Property area in hectares.
states VARCHAR[]
States Parties (country names).
states_iso3 VARCHAR[]
States Parties as ISO 3166-1 alpha-3 codes.
states_iso2 VARCHAR[]
States Parties as ISO 3166-1 alpha-2 codes (as published).
region VARCHAR
UNESCO region, e.g. 'Europe and North America', 'Arab States'.
region_code VARCHAR
UNESCO region code, e.g. 'EUR', 'ARB'.
transboundary BOOLEAN
True when the site spans several States Parties.
latitude DOUBLE
Latitude of the site's main point (WGS84).
longitude DOUBLE
Longitude of the site's main point (WGS84).
components_count INTEGER
Number of component parts of a serial property.
short_description VARCHAR
Short description (English).
url VARCHAR
The site's page on whc.unesco.org.
uuid VARCHAR
UNESCO open-data record UUID.
Examples (2)

Sites on the List of World Heritage in Danger, by category

SELECT category, count(*) AS sites
FROM un.heritage.sites()
WHERE in_danger
GROUP BY category
ORDER BY category;

World Heritage sites in Syria with their inscription year and criteria

SELECT name, year_inscribed, criteria
FROM un.heritage.sites(country := 'SYR')
ORDER BY year_inscribed, name;
Link
main 1 table · 2 functions

The bundled UN M49 country and area code standard, with code conversion helpers.

Schema examples (3)
Examples (3)

Convert SDG-style M49 area codes to ISO alpha-3 (regions give NULL)

SELECT code, un.main.iso3_from_m49(code) AS iso3
FROM (VALUES ('4'), ('356'), ('150')) t(code)
ORDER BY code;

Convert ISO alpha-3 codes to M49 (unknown codes give NULL)

SELECT iso3, un.main.m49_from_iso3(iso3) AS m49
FROM (VALUES ('AFG'), ('bra'), ('XXX')) t(iso3)
ORDER BY iso3;

Countries and small island developing states in each Oceania sub-region

SELECT subregion_name, count(*) AS countries,
  count(*) FILTER (WHERE sids) AS sids
FROM un.main.m49_countries
WHERE region_name = 'Oceania'
GROUP BY subregion_name
ORDER BY subregion_name;
Tables
m49_countries 3 examples13 cols

UN M49 country and area codes with ISO alpha-2/alpha-3 codes, regions and LDC/LLDC/SIDS flags

Columns
m49not null VARCHAR
3-digit M49 code with leading zeros, e.g. '004'.
country_or_area VARCHAR
Country or area name (English).
iso_alpha2 VARCHAR
ISO 3166-1 alpha-2 code, e.g. 'AF' (NULL for a few areas).
iso_alpha3 VARCHAR
ISO 3166-1 alpha-3 code, e.g. 'AFG' (NULL for a few areas).
region_code VARCHAR
M49 region code, e.g. '142' Asia (NULL for Antarctica).
region_name VARCHAR
Region: Africa, Americas, Asia, Europe or Oceania.
subregion_code VARCHAR
M49 sub-region code, e.g. '034'.
subregion_name VARCHAR
Sub-region name, e.g. 'Southern Asia'.
intermediate_region_code VARCHAR
Intermediate region code, e.g. '014'; often NULL.
intermediate_region_name VARCHAR
Intermediate region name, e.g. 'Eastern Africa'.
ldc BOOLEAN
True for Least Developed Countries.
lldc BOOLEAN
True for Land Locked Developing Countries.
sids BOOLEAN
True for Small Island Developing States.
ConstraintsPRIMARY KEY (m49)
Examples (3)

Countries and small island developing states in each Oceania sub-region

SELECT subregion_name, count(*) AS countries,
  count(*) FILTER (WHERE sids) AS sids
FROM un.main.m49_countries
WHERE region_name = 'Oceania'
GROUP BY subregion_name
ORDER BY subregion_name;

Least developed countries per region

SELECT region_name, count(*) AS ldcs
FROM un.main.m49_countries
WHERE ldc
GROUP BY region_name
ORDER BY region_name;

Look up India by its ISO code

SELECT m49, country_or_area, subregion_name
FROM un.main.m49_countries
WHERE iso_alpha3 = 'IND';
Link
Scalar functions
iso3_from_m49 (code VARCHAR) 1 example

Convert a UN M49 country code ('4', '004' or '356') to its ISO 3166-1 alpha-3 code

Arguments
code VARCHAR
M49 numeric code as text, e.g. '4' or '004'; NULL gives NULL.
ReturnsVARCHAR
Example

Convert SDG-style M49 area codes to ISO alpha-3 (regions give NULL)

SELECT code, un.main.iso3_from_m49(code) AS iso3
FROM (VALUES ('4'), ('356'), ('150')) t(code)
ORDER BY code;
Link
m49_from_iso3 (code VARCHAR) 1 example

Convert an ISO 3166-1 alpha-3 country code ('IND') to its 3-digit UN M49 code ('356')

Arguments
code VARCHAR
ISO alpha-3 country code, e.g. 'IND'; NULL gives NULL.
ReturnsVARCHAR
Example

Convert ISO alpha-3 codes to M49 (unknown codes give NULL)

SELECT iso3, un.main.m49_from_iso3(iso3) AS m49
FROM (VALUES ('AFG'), ('bra'), ('XXX')) t(iso3)
ORDER BY iso3;
Link
population 2 tables · 1 function

UN DESA World Population Prospects: population, fertility, mortality and migration estimates and projections to 2100. The indicator and location lists are keyless; data needs a un_population secret.

Schema examples (3)
Examples (3)

India's total population (thousands), 2020-2025 (needs a un_population secret)

SELECT year, value AS population_thousands
FROM un.population.data('49')
WHERE country_iso3 = 'IND' AND year BETWEEN 2020 AND 2025 AND sex = 'Both sexes'
ORDER BY year;

Data Portal indicators per topic

SELECT topic, count(*) AS indicators
FROM un.population.indicators
GROUP BY topic
ORDER BY topic;

Data Portal ids of India and Nigeria

SELECT location_id, name
FROM un.population.locations
WHERE country_iso3 IN ('IND', 'NGA')
ORDER BY name;
Tables
indicators 1 example13 cols

The UN Population Division Data Portal indicators (population, fertility, mortality, migration ...)

Columns
indicator_idnot null INTEGER
Numeric indicator id, e.g. 49 (total population); pass to population.data().
short_name VARCHAR
Short code, e.g. 'TPopulation'.
name VARCHAR
Indicator name with unit.
description VARCHAR
What the indicator measures.
topic VARCHAR
Topic, e.g. 'Population', 'Fertility', 'Mortality'.
source VARCHAR
Source dataset, e.g. 'World Population Prospects 2024'.
source_year INTEGER
Revision year of the source.
value_type VARCHAR
Value type, e.g. 'number', 'percent', 'rate'.
unit VARCHAR
Unit label, e.g. 'thousands', 'per cent'.
unit_scaling DOUBLE
Multiply value by this to get base units (e.g. 1000 for thousands).
has_age BOOLEAN
True when the indicator is broken down by age.
has_sex BOOLEAN
True when the indicator is broken down by sex.
has_variant BOOLEAN
True when the indicator has projection variants.
ConstraintsPRIMARY KEY (indicator_id)
Example

Data Portal indicators per topic

SELECT topic, count(*) AS indicators
FROM un.population.indicators
GROUP BY topic
ORDER BY topic;
Link
locations 1 example6 cols

Countries and areas of the UN Population Division Data Portal with ids and ISO codes

Columns
location_idnot null INTEGER
Location id (the M49 numeric code for countries, e.g. 356).
name VARCHAR
Location name.
country_iso3 VARCHAR
ISO alpha-3 code.
iso2 VARCHAR
ISO alpha-2 code.
latitude DOUBLE
Latitude of the location's centroid, in decimal degrees (WGS84).
longitude DOUBLE
Longitude of the location's centroid, in decimal degrees (WGS84).
ConstraintsPRIMARY KEY (location_id)
Example

Data Portal ids of India and Nigeria

SELECT location_id, name
FROM un.population.locations
WHERE country_iso3 IN ('IND', 'NGA')
ORDER BY name;
Link
Table functions
data (indicator VARCHAR, location := VARCHAR, variants := VARCHAR) 1 example

UN World Population Prospects estimates and projections by indicator, country, year, sex and age

Positional arguments
indicator VARCHAR
Indicator id(s) from population.indicators, e.g. '49' (total population) or '49,19'.
Named arguments
location := VARCHAR
Countries as ISO alpha-3 or location ids, comma-separated ('IND,NGA'); or filter WHERE country_iso3. · default ""
variants := VARCHAR
Projection variant id(s) or 'all'; default '' = the median variant (estimates + median projection). · default ""
Returns columns
indicator_id INTEGER
Indicator id.
indicator VARCHAR
Indicator short name, e.g. 'TPopulation'.
indicator_name VARCHAR
Indicator display name.
location_id INTEGER
Location id (M49 number for countries).
location VARCHAR
Location name.
country_iso3 VARCHAR
ISO alpha-3 code of the location (NULL for aggregates).
year INTEGER
Year (start of the period for multi-year periods).
time_label VARCHAR
Period as published, e.g. '2024' or '2020-2025'.
variant VARCHAR
Projection variant, e.g. 'Median', 'Estimates', 'High', 'Low'.
sex VARCHAR
Sex: 'Both sexes', 'Female' or 'Male'.
age_label VARCHAR
Age group label, e.g. 'Total', '0-4', '15-49'.
age_start INTEGER
First age of the group.
age_end INTEGER
Last age of the group (NULL for open-ended groups).
category VARCHAR
Category dimension, e.g. 'All women' for family planning indicators.
estimate_type VARCHAR
Estimate type as published.
estimate_method VARCHAR
Estimate method as published (e.g. 'Interpolation').
source VARCHAR
Source dataset, e.g. 'World Population Prospects 2024'.
revision INTEGER
Revision year of the source.
value DOUBLE
Value in the indicator's unit (see population.indicators.unit).
Example

India's total population (thousands), 2020-2025 (needs a un_population secret)

SELECT year, value AS population_thousands
FROM un.population.data('49')
WHERE country_iso3 = 'IND' AND year BETWEEN 2020 AND 2025 AND sex = 'Both sexes'
ORDER BY year;
Link
refugees 5 tables

UNHCR refugee statistics: forcibly displaced and stateless populations, asylum applications and decisions, and durable solutions, by year, country of origin and country of asylum.

Schema examples (6)
Examples (6)

Refugees from Syria living in Germany at the end of 2023

SELECT value AS refugees
FROM un.refugees.populations
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023 AND measure = 'refugees';

The five countries hosting the most Syrian refugees in 2023

SELECT asylum_name, value
FROM un.refugees.populations
WHERE origin_iso3 = 'SYR' AND year = 2023 AND measure = 'refugees'
ORDER BY value DESC
LIMIT 5;

Syrian asylum applications in Germany in 2023 by procedure stage

SELECT decision_level, sum(value) AS applications
FROM un.refugees.asylum_applications
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023
GROUP BY decision_level
ORDER BY decision_level;

Outcomes of Syrian asylum claims decided in Germany in 2023

SELECT measure, sum(value) AS decisions
FROM un.refugees.asylum_decisions
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023
GROUP BY measure
ORDER BY measure;
2 more examples

Where Syrian refugees returning home in 2023 came back from

SELECT asylum_name, value
FROM un.refugees.solutions
WHERE origin_iso3 = 'SYR' AND year = 2023 AND measure = 'returned_refugees'
ORDER BY value DESC
LIMIT 5;

Countries whose UNHCR code differs from the ISO code

SELECT unhcr_code, country_iso3, name
FROM un.refugees.countries
WHERE unhcr_code <> country_iso3
ORDER BY unhcr_code
LIMIT 10;
Tables
asylum_applications 1 example13 cols

UNHCR asylum applications lodged each year, by origin, asylum country and procedure

Columns
year INTEGER
Calendar year (end-year stock, or flows during the year).
origin_iso3 VARCHAR
Country of origin, ISO 3166-1 alpha-3 (NULL when unknown or stateless).
origin_code VARCHAR
Country of origin, UNHCR 3-letter code (e.g. 'SYR'; differs from ISO for some).
origin_name VARCHAR
Country of origin name as UNHCR writes it.
asylum_iso3 VARCHAR
Country of asylum or residence, ISO 3166-1 alpha-3.
asylum_code VARCHAR
Country of asylum, UNHCR code (e.g. 'GFR' for Germany).
asylum_name VARCHAR
Country of asylum name as UNHCR writes it.
procedure_type VARCHAR
G government, U UNHCR, J joint procedure.
application_type VARCHAR
Application type code, e.g. N new, A appeal.
decision_level VARCHAR
Procedure stage, e.g. FI first instance, AR appeal.
count_basis VARCHAR
P persons or C cases.
measure VARCHAR
What is counted; see the function description for the values.
value DOUBLE
Number of people (or applications / decisions).
Example

Syrian asylum applications in Germany in 2023 by procedure stage

SELECT decision_level, sum(value) AS applications
FROM un.refugees.asylum_applications
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023
GROUP BY decision_level
ORDER BY decision_level;
Link
asylum_decisions 1 example12 cols

UNHCR decisions on asylum claims each year: recognized, other protection, rejected, closed

Columns
year INTEGER
Calendar year (end-year stock, or flows during the year).
origin_iso3 VARCHAR
Country of origin, ISO 3166-1 alpha-3 (NULL when unknown or stateless).
origin_code VARCHAR
Country of origin, UNHCR 3-letter code (e.g. 'SYR'; differs from ISO for some).
origin_name VARCHAR
Country of origin name as UNHCR writes it.
asylum_iso3 VARCHAR
Country of asylum or residence, ISO 3166-1 alpha-3.
asylum_code VARCHAR
Country of asylum, UNHCR code (e.g. 'GFR' for Germany).
asylum_name VARCHAR
Country of asylum name as UNHCR writes it.
procedure_type VARCHAR
G government, U UNHCR, J joint procedure.
decision_level VARCHAR
Procedure stage, e.g. FI first instance, AR appeal.
count_basis VARCHAR
P persons or C cases.
measure VARCHAR
What is counted; see the function description for the values.
value DOUBLE
Number of people (or applications / decisions).
Example

Outcomes of Syrian asylum claims decided in Germany in 2023

SELECT measure, sum(value) AS decisions
FROM un.refugees.asylum_decisions
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023
GROUP BY measure
ORDER BY measure;
Link
countries 1 example6 cols

UNHCR's country list, mapping UNHCR 3-letter codes to ISO alpha-3 codes and regions

Columns
unhcr_codenot null VARCHAR
UNHCR 3-letter country code, e.g. 'ALG'.
country_iso3 VARCHAR
ISO 3166-1 alpha-3 code, e.g. 'DZA'.
iso2 VARCHAR
ISO 3166-1 alpha-2 code.
name VARCHAR
Short English name.
major_area VARCHAR
UNHCR major area, e.g. 'Africa'.
region VARCHAR
Region, e.g. 'Northern Africa'.
ConstraintsPRIMARY KEY (unhcr_code)
Example

Countries whose UNHCR code differs from the ISO code

SELECT unhcr_code, country_iso3, name
FROM un.refugees.countries
WHERE unhcr_code <> country_iso3
ORDER BY unhcr_code
LIMIT 10;
Link
populations 2 examples9 cols

UNHCR end-year populations: refugees, asylum-seekers, IDPs, stateless and others, by origin and asylum

Columns
year INTEGER
Calendar year (end-year stock, or flows during the year).
origin_iso3 VARCHAR
Country of origin, ISO 3166-1 alpha-3 (NULL when unknown or stateless).
origin_code VARCHAR
Country of origin, UNHCR 3-letter code (e.g. 'SYR'; differs from ISO for some).
origin_name VARCHAR
Country of origin name as UNHCR writes it.
asylum_iso3 VARCHAR
Country of asylum or residence, ISO 3166-1 alpha-3.
asylum_code VARCHAR
Country of asylum, UNHCR code (e.g. 'GFR' for Germany).
asylum_name VARCHAR
Country of asylum name as UNHCR writes it.
measure VARCHAR
What is counted; see the function description for the values.
value DOUBLE
Number of people (or applications / decisions).
Examples (2)

Refugees from Syria living in Germany at the end of 2023

SELECT value AS refugees
FROM un.refugees.populations
WHERE origin_iso3 = 'SYR' AND asylum_iso3 = 'DEU' AND year = 2023 AND measure = 'refugees';

The five countries hosting the most Syrian refugees in 2023

SELECT asylum_name, value
FROM un.refugees.populations
WHERE origin_iso3 = 'SYR' AND year = 2023 AND measure = 'refugees'
ORDER BY value DESC
LIMIT 5;
Link
solutions 1 example9 cols

UNHCR durable solutions each year: refugee returns, resettlement, naturalisation, IDP returns

Columns
year INTEGER
Calendar year (end-year stock, or flows during the year).
origin_iso3 VARCHAR
Country of origin, ISO 3166-1 alpha-3 (NULL when unknown or stateless).
origin_code VARCHAR
Country of origin, UNHCR 3-letter code (e.g. 'SYR'; differs from ISO for some).
origin_name VARCHAR
Country of origin name as UNHCR writes it.
asylum_iso3 VARCHAR
Country of asylum or residence, ISO 3166-1 alpha-3.
asylum_code VARCHAR
Country of asylum, UNHCR code (e.g. 'GFR' for Germany).
asylum_name VARCHAR
Country of asylum name as UNHCR writes it.
measure VARCHAR
What is counted; see the function description for the values.
value DOUBLE
Number of people (or applications / decisions).
Example

Where Syrian refugees returning home in 2023 came back from

SELECT asylum_name, value
FROM un.refugees.solutions
WHERE origin_iso3 = 'SYR' AND year = 2023 AND measure = 'returned_refugees'
ORDER BY value DESC
LIMIT 5;
Link
sdg 5 tables · 1 function

The UN SDG Global Database: the 17 goals, their targets, indicators and data series, and series observations by country or region and year.

Schema examples (7)
Examples (7)

Share of India's population below the international poverty line, by year

SELECT year, value
FROM un.sdg.data('SI_POV_DAY1')
WHERE country_iso3 = 'IND' AND sex = 'BOTHSEX' AND age = 'ALLAGE' AND location = 'ALLAREA'
ORDER BY year;

Average poverty rate of India and Bangladesh by year, labelled with the M49 region

SELECT d.year, m.region_name, round(avg(d.value), 1) AS avg_poverty_pct
FROM un.sdg.data('SI_POV_DAY1') d
JOIN un.main.m49_countries m ON m.iso_alpha3 = d.country_iso3
WHERE d.country_iso3 IN ('IND', 'BGD') AND d.year BETWEEN 2004 AND 2022 AND d.age = 'ALLAGE' AND d.location = 'ALLAREA'
GROUP BY ALL
ORDER BY ALL;

All 17 goals in numeric order

SELECT goal, title FROM un.sdg.goals ORDER BY goal::INTEGER;

Number of targets under each goal

SELECT goal, count(*) AS targets
FROM un.sdg.targets
GROUP BY goal
ORDER BY goal::INTEGER;
3 more examples

Indicators under target 1.1 and the series that measure them

SELECT indicator, description, series_codes
FROM un.sdg.indicators
WHERE target = '1.1'
ORDER BY indicator;

Series that measure indicator 1.1.1 (extreme poverty)

SELECT series_code, description
FROM un.sdg.series
WHERE list_contains(indicators, '1.1.1')
ORDER BY series_code;

Countries versus regional groupings in the SDG area list

SELECT count(*) FILTER (WHERE country_iso3 IS NOT NULL) AS countries,
  count(*) FILTER (WHERE country_iso3 IS NULL) AS other_areas
FROM un.sdg.geoareas;
Tables
geoareas 1 example4 cols

Countries, areas and regional groupings the SDG database reports, with M49 and ISO codes

Columns
area_codenot null VARCHAR
SDG area code as the API writes it (M49 without leading zeros).
m49 VARCHAR
3-digit M49 code with leading zeros, e.g. '004'.
country_iso3 VARCHAR
ISO 3166-1 alpha-3 code; NULL for regions and groupings.
area_name VARCHAR
Country, area or region name.
ConstraintsPRIMARY KEY (area_code)
Example

Countries versus regional groupings in the SDG area list

SELECT count(*) FILTER (WHERE country_iso3 IS NOT NULL) AS countries,
  count(*) FILTER (WHERE country_iso3 IS NULL) AS other_areas
FROM un.sdg.geoareas;
Link
goals 1 example3 cols

The 17 Sustainable Development Goals with their titles and descriptions

Columns
goalnot null VARCHAR
Goal number as text, '1' to '17'.
title VARCHAR
Short goal title, e.g. 'End poverty in all its forms everywhere'.
description VARCHAR
Longer description of the goal.
ConstraintsPRIMARY KEY (goal)
Example

All 17 goals in numeric order

SELECT goal, title FROM un.sdg.goals ORDER BY goal::INTEGER;
Link
indicators 1 example6 cols

The SDG indicators (1.1.1 ...) with their wording, tier and data series codes

Columns
indicatornot null VARCHAR
Indicator code, e.g. '1.1.1'.
goal VARCHAR
Goal number.
target VARCHAR
Target code, e.g. '1.1'.
description VARCHAR
Indicator wording.
tier VARCHAR
Tier classification ('1', '2', ...) as published.
series_codes VARCHAR[]
Codes of the data series measuring this indicator; pass one to sdg.data().
ConstraintsPRIMARY KEY (indicator)
Example

Indicators under target 1.1 and the series that measure them

SELECT indicator, description, series_codes
FROM un.sdg.indicators
WHERE target = '1.1'
ORDER BY indicator;
Link
series 1 example6 cols

The 700+ SDG data series in the current release, with the indicators they measure

Columns
series_codenot null VARCHAR
Series code, e.g. 'SI_POV_DAY1'; pass it to sdg.data().
description VARCHAR
What the series measures, with its unit in parentheses.
goals VARCHAR[]
Goals the series reports on.
targets VARCHAR[]
Targets the series reports on.
indicators VARCHAR[]
Indicator codes the series measures.
release VARCHAR
Database release the series is from, e.g. '2026.Q3.G.01'.
ConstraintsPRIMARY KEY (series_code)
Example

Series that measure indicator 1.1.1 (extreme poverty)

SELECT series_code, description
FROM un.sdg.series
WHERE list_contains(indicators, '1.1.1')
ORDER BY series_code;
Link
targets 1 example3 cols

The 169 SDG targets, each with its goal and wording

Columns
targetnot null VARCHAR
Target code, e.g. '1.1' or '17.a'.
goal VARCHAR
Goal number the target belongs to.
title VARCHAR
Target text.
ConstraintsPRIMARY KEY (target)
Example

Number of targets under each goal

SELECT goal, count(*) AS targets
FROM un.sdg.targets
GROUP BY goal
ORDER BY goal::INTEGER;
Link
Table functions
data (series VARCHAR) 2 examples

SDG Global Database observations for one or more data series, by area, year and dimension

Arguments
series VARCHAR
Series code, e.g. 'SI_POV_DAY1', or a comma-separated list. Find codes in sdg.series.
Returns columns
series_code VARCHAR
Series code, e.g. 'SI_POV_DAY1'.
series_description VARCHAR
What the series measures, with unit.
goal VARCHAR[]
Goals the series reports on.
target VARCHAR[]
Targets the series reports on.
indicator VARCHAR[]
Indicator codes, e.g. ['1.1.1'].
area_code VARCHAR
SDG area code (M49 without leading zeros, e.g. '356').
m49 VARCHAR
3-digit M49 code, e.g. '356'; NULL for non-numeric area codes.
country_iso3 VARCHAR
ISO 3166-1 alpha-3 code; NULL for regions and groupings.
area_name VARCHAR
Country, area or region name.
year INTEGER
Observation year (the start of the time period).
time_detail VARCHAR
Finer period detail when published, e.g. '2015-2017'.
value DOUBLE
Numeric value; NULL when the published value is not a number.
value_text VARCHAR
The value exactly as published (may be '<1', 'NaN', 'N').
value_type VARCHAR
Published value type, e.g. 'Float'.
unit VARCHAR
Units attribute code, e.g. 'PERCENT', 'NUMBER', 'CON_USD'.
nature VARCHAR
Nature of data code: C country, CA adjusted, E estimated, M modelled, G global.
sex VARCHAR
Sex dimension code (BOTHSEX, FEMALE, MALE); NULL when not disaggregated.
age VARCHAR
Age dimension code, e.g. 'ALLAGE', '15-24'; NULL when not disaggregated.
location VARCHAR
Urban/rural dimension (ALLAREA, URBAN, RURAL); NULL when absent.
reporting_type VARCHAR
N national, G global (UN-estimated), R regional.
lower_bound DOUBLE
Lower confidence bound when published.
upper_bound DOUBLE
Upper confidence bound when published.
base_period VARCHAR
Base period of prices or indices, e.g. '2021'.
source VARCHAR
Data source named by the custodian agency.
footnotes VARCHAR[]
Footnotes attached to the observation.
dimensions MAP(VARCHAR, VARCHAR)
Every dimension of the observation, name -> code.
attributes MAP(VARCHAR, VARCHAR)
Every attribute of the observation, name -> code.
Examples (2)

Share of India's population below the international poverty line, by year

SELECT year, value
FROM un.sdg.data('SI_POV_DAY1')
WHERE country_iso3 = 'IND' AND sex = 'BOTHSEX' AND age = 'ALLAGE' AND location = 'ALLAREA'
ORDER BY year;

Average poverty rate of India and Bangladesh by year, labelled with the M49 region

SELECT d.year, m.region_name, round(avg(d.value), 1) AS avg_poverty_pct
FROM un.sdg.data('SI_POV_DAY1') d
JOIN un.main.m49_countries m ON m.iso_alpha3 = d.country_iso3
WHERE d.country_iso3 IN ('IND', 'BGD') AND d.year BETWEEN 2004 AND 2022 AND d.age = 'ALLAGE' AND d.location = 'ALLAREA'
GROUP BY ALL
ORDER BY ALL;
Link
uis 3 tables · 1 function

UNESCO Institute for Statistics: education, science, culture and communication indicators and their observations by country or region and year.

Schema examples (5)
Examples (5)

Primary completion rate in Brazil and the United States, 2015-2020

SELECT geo_unit, year, round(value, 1) AS completion_rate
FROM un.uis.data(indicator := 'CR.1')
WHERE country_iso3 IN ('BRA', 'USA') AND year BETWEEN 2015 AND 2020
ORDER BY geo_unit, year;

Every UIS indicator value for Brazil in 2020, with indicator names

SELECT d.indicator_code, i.name, d.value
FROM un.uis.data(geo_unit := 'BRA') d
JOIN un.uis.indicators i USING (indicator_code)
WHERE d.year = 2020
ORDER BY d.indicator_code;

Number of UIS indicators per theme

SELECT theme, count(*) AS indicators
FROM un.uis.indicators
GROUP BY theme
ORDER BY theme;

Regional groupings and how many regions each defines

SELECT region_group, count(*) AS regions
FROM un.uis.geo_units
WHERE type = 'REGIONAL'
GROUP BY region_group
ORDER BY regions DESC;
1 more example

The current default UIS data version

SELECT version, publication_date FROM un.uis.versions WHERE is_default;
Tables
geo_units 1 example5 cols

Countries and regional groupings that UIS publishes data for

Columns
geo_unitnot null VARCHAR
Geo unit id: ISO alpha-3 for countries, 'GROUP: Name' for regions.
name VARCHAR
Country or region name.
type VARCHAR
NATIONAL or REGIONAL.
region_group VARCHAR
Regional grouping scheme, e.g. 'SDG', 'WB', 'UIS'; NULL for countries.
country_iso3 VARCHAR
ISO alpha-3 code for national units listed in M49, else NULL.
ConstraintsPRIMARY KEY (geo_unit)
Example

Regional groupings and how many regions each defines

SELECT region_group, count(*) AS regions
FROM un.uis.geo_units
WHERE type = 'REGIONAL'
GROUP BY region_group
ORDER BY regions DESC;
Link
indicators 1 example9 cols

The ~5,500 UNESCO UIS indicators (education, science, culture) with theme, coverage and record count

Columns
indicator_codenot null VARCHAR
UIS indicator code, e.g. 'CR.1'; pass it to uis.data().
name VARCHAR
Indicator name.
theme VARCHAR
EDUCATION, SCIENCE_TECHNOLOGY_INNOVATION, CULTURE or DEMOGRAPHIC_SOCIOECONOMIC.
last_data_update DATE
Date of the latest data release for the indicator.
last_data_update_description VARCHAR
Release name, e.g. 'November 2026 Data Release'.
total_record_count BIGINT
Records published for the indicator (all countries and years).
first_year INTEGER
Earliest year with data.
last_year INTEGER
Latest year with data.
geo_unit_types VARCHAR[]
Geo unit types with data: NATIONAL and/or REGIONAL.
ConstraintsPRIMARY KEY (indicator_code)
Example

Number of UIS indicators per theme

SELECT theme, count(*) AS indicators
FROM un.uis.indicators
GROUP BY theme
ORDER BY theme;
Link
versions 1 example4 cols

Published UIS data versions, newest first, with the default version flagged

Columns
versionnot null VARCHAR
Data version id, e.g. '20261110-392b682a'.
publication_date TIMESTAMP WITH TIME ZONE
When the version was published.
is_default BOOLEAN
True for the current default version.
themes STRUCT of 3 fields[]
Per-theme release status: theme, last_update, description.
STRUCT[] 3 fields
  • themeVARCHAR
  • last_updateDATE
  • descriptionVARCHAR
ConstraintsPRIMARY KEY (version)
Example

The current default UIS data version

SELECT version, publication_date FROM un.uis.versions WHERE is_default;
Link
Table functions
data (geo_unit := VARCHAR, indicator := VARCHAR, version := VARCHAR) 2 examples

UNESCO UIS education, science and culture observations by indicator, country or region, and year

Named arguments
geo_unit := VARCHAR
Geo unit id(s), comma-separated: ISO alpha-3 ('BRA,USA') or region ids from uis.geo_units. · default ""
indicator := VARCHAR
Indicator code(s), comma-separated, e.g. 'CR.1' or 'CR.1,CR.2'. · default ""
version := VARCHAR
Data version from uis.versions; default '' = the current default version. · default ""
Returns columns
indicator_code VARCHAR
UIS indicator code.
geo_unit VARCHAR
Geo unit id (ISO alpha-3 for countries).
country_iso3 VARCHAR
ISO alpha-3 code for countries, NULL for regions.
year INTEGER
Reference year.
value DOUBLE
Indicator value (units are part of the indicator definition).
magnitude VARCHAR
Magnitude flag, e.g. 'NIL' or 'NA', when published.
qualifier VARCHAR
Qualifier flag, e.g. 'UIS_EST' (UIS estimate), when published.
footnotes STRUCT(type VARCHAR, subtype VARCHAR, value VARCHAR)[]
Footnotes: list of (type, subtype, value).
version VARCHAR
Data version the value comes from.
Examples (2)

Primary completion rate in Brazil and the United States, 2015-2020

SELECT geo_unit, year, round(value, 1) AS completion_rate
FROM un.uis.data(indicator := 'CR.1')
WHERE country_iso3 IN ('BRA', 'USA') AND year BETWEEN 2015 AND 2020
ORDER BY geo_unit, year;

Every UIS indicator value for Brazil in 2020, with indicator names

SELECT d.indicator_code, i.name, d.value
FROM un.uis.data(geo_unit := 'BRA') d
JOIN un.uis.indicators i USING (indicator_code)
WHERE d.year = 2020
ORDER BY d.indicator_code;
Link

Credentials

The secret type un declares, as reported by the worker itself.

un_population

How to get these credentials

Bearer token for the UN DESA Population Division Data Portal API (population.data).

secret.sql
CREATE SECRET un_population (
    TYPE un_population,
    token '<UN_POPULATION_TOKEN>'  -- secret
);
Key Type Required Description
token secret VARCHAR — Data Portal API token (the 'GENERATE TOKEN' button on the API page), sent as a bearer token.

The worker doesn't mark which keys are required.

Needed by data

Create the secret in the same session, after attaching un — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Life expectancy in 2019 in three South Asian countries, with M49 names

SELECT d.country_iso3, m.country_or_area, d.value
FROM un.health.data('WHOSIS_000001') d
JOIN un.main.m49_countries m ON m.iso_alpha3 = d.country_iso3
WHERE d.country_iso3 IN ('BGD', 'IND', 'PAK') AND d.year = 2019 AND d.sex = 'SEX_BTSX'
ORDER BY d.value DESC

Uses datadatadatadatam49_countries

Decode the SEX dimension

SELECT code, title FROM un.health.dimension_values('SEX') ORDER BY code

Uses dimension_values

Find the life expectancy indicators

SELECT indicator_code, name
FROM un.health.indicators
WHERE name ILIKE '%life expectancy%'
ORDER BY indicator_code

Uses indicatorsindicatorsindicatorsindicators

Number of countries in each WHO region

SELECT who_region, count(*) AS countries
FROM un.health.countries
GROUP BY who_region
ORDER BY who_region

Uses countriescountries

Dimensions about age

SELECT dimension, title
FROM un.health.dimensions
WHERE title ILIKE '%age%'
ORDER BY dimension

Uses dimensions

Sites on the List of World Heritage in Danger, by category

SELECT category, count(*) AS sites
FROM un.heritage.sites()
WHERE in_danger
GROUP BY category
ORDER BY category

Uses sites

27 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the un worker, how many least developed countries (LDCs) are in Africa according to M49?
  • Using the un worker, what is the UN M49 code of India (ISO code IND)?
  • Using the un worker, how many Sustainable Development Goals does the SDG database list?
  • Using the un worker's UNHCR data, how many refugees from Syria were in Germany at the end of 2023?
  • Using the un worker's WHO data, what was life expectancy at birth for both sexes in India in 2019 (indicator WHOSIS_000001)?
  • Using the un worker, how many World Heritage sites are currently on the List in Danger?

United Nations is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.