# State/Province Code

Key: `geography.location.state_code`

Two- or three-letter state or province abbreviation. Locale-specific due to country-dependent subdivision codes (e.g., US states, CA provinces, AU states/territories). The US form is the USPS abbreviation; the AU form is the ISO 3166-2:AU subdivision code without its country prefix (AU-NSW is the ISO 3166-2 form of NSW).

Page: <https://meridian.online/docs/finetype/types/geography/location/state_code>

Samples: `CA`, `NY`, `TX`, `FL`, `ON`, `NSW`

## Use it

Shell

```shell
finetype infer -i 'CA' --mode column
# → geography.location.state_code
```

DuckDB

```sql
SELECT ft_infer('CA');
-- → 'geography.location.state_code'
```

Cast template: {col} is your column

```sql
UPPER(CAST({col} AS VARCHAR))
```

## Background

### Origin

The modern two-letter codes for US states and territories originated in October 1963 with Publication 59.[[1]](https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations) The US codes arrived three months after ZIP codes were introduced in July 1963.[[1]](https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations) Only one US state code has changed since 1963: Nebraska moved from NB to NE in November 1969 to avoid confusion with Canada's New Brunswick.[[1]](https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations)

Canada Post's two-letter provincial and territorial abbreviations replaced the inconsistent traditional system that Canadians used until the 1990s.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories) In 1991, the Canadian code for Quebec was changed from PQ to QC.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories) On 21 October 2002, the postal abbreviation for Newfoundland and Labrador was changed from NF to NL.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories) Before the Nunavut code NU took effect in December 2000, NT covered both Nunavut and the Northwest Territories.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories) Canada avoided abbreviations that overlap with US state codes, which is why NV was not used for Nunavut.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories)

ISO 3166-2, published by the International Organization for Standardization and first published in 1998, defines codes for the principal subdivisions of countries.[[3]](https://en.wikipedia.org/wiki/ISO_3166-2) For Canada, ISO adopted the existing Canada Post abbreviations.[[2]](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories)

### Use

The US Census Bureau's code list gives each state both a numeric State FIPS code and a state postal abbreviation.[[4]](https://www.census.gov/library/reference/code-lists/ansi.html)

## Sources

1. [List of U.S. state and territory abbreviations](https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations) — secondary source
2. [Canadian postal abbreviations for provinces and territories](https://en.wikipedia.org/wiki/Canadian_postal_abbreviations_for_provinces_and_territories) — secondary source
3. [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) — secondary source
4. [American National Standards Institute (ANSI), Federal Information Processing Series (FIPS), and Other Standardized Geographic Codes](https://www.census.gov/library/reference/code-lists/ansi.html) — organisation

## How it's detected

Separated from country\_code remap (state\_code→country\_code was causing US state abbreviations like OR, CA, FL to train as country codes). Locale-specific: US (50 states + DC + territories, the freely associated states FM, MH and PW, and the military codes AA, AE and AP, as in USPS Publication 28 Appendix B), CA (13 provinces/territories), AU (8 states/territories, ISO 3166-2:AU). AU codes are 2-3 letters, so the universal pattern is ^\[A-Z\]{2,3}$. FM, MH, PW and AE are also ISO 3166-1 country codes, so a bare column of them is ambiguous between the two types (geo\_code\_membership\_vote leaves such a column alone). For discrimination a value counts only as two uppercase letters or an EN\_AU three-letter code, so three-letter airport and currency codes do not; the other three-letter forms the pattern accepts conform but are not counted.
