On this page
Countries by ISO code
H2Read onlyScripts Gallery
A list parameter in practice: pass several codes at once, each sent to the database as its own typed value.
Verification status. The output below was captured with this query on the WORLD sample database, as shown in List parameters. The header lines added here do not change the result.
When to use it
- Look up a list of keys from a ticket in one call.
- See how
LIST OF TEXTbecomesIN (?, ?, ?).
The Script
Download world-countries-by-codes.sql
-- @description: Countries by ISO code
-- @tags: world, sample, geo, list
-- @status: stable
-- @access: read
-- @dialect: H2
-- @param codes LIST OF TEXT "Three-letter country codes"
SELECT CODE, NAME FROM COUNTRY WHERE CODE IN (${codes}) ORDER BY CODE;
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
codes | LIST OF TEXT | Required | Three-letter country codes |
Install and run it
- Save the file in your Scripts Library folder (
scriptsin the installation folder by default), for example asgallery/world-countries-by-codes.sql. - Open the sample database:
CONNECT WORLD;. - Check what it declares:
LIB SHOW gallery/world-countries-by-codes.sql; - Run it:
@gallery/world-countries-by-codes.sql codes=('FRA', 'DEU', 'ITA');
What you get
One row per code found, with the country name, sorted by code.
@countries/by-codes.sql codes=('FRA', 'DEU', 'ITA');
SELECT CODE, NAME FROM COUNTRY WHERE CODE IN (${codes}) ORDER BY CODE
-- codes = ('FRA', 'DEU', 'ITA')
|----|----------------------------------------------------|
|CODE|NAME |
|----|----------------------------------------------------|
|DEU |Germany |
|FRA |France |
|ITA |Italy |
|----|----------------------------------------------------|
3 rows fetched in 0 ms.
Limits
- A list holds 1 to 1000 values, without
NULL. - One value is still written as a list:
codes=('FRA').
Related
Found something wrong or unclear on this page? Tell us, with the page address.