postcode
postcode · UK and international postal code types with validation and indexed prefix search
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3815 | postcode | postcode | 2.1.1 | TYPE | BSD-2-Clause | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | country address_standardizer |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| el8.aarch64 | N/A | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| el9.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| el9.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| el10.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| el10.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| d12.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| d12.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| d13.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| d13.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u22.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u22.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u24.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u24.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u26.x86_64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
| u26.aarch64 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 | PIGSTY 2.1.1 |
Source
github.com/John-Cameron-Burns/pg-postcode
postcode-2.1.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
postcode is distributed as 2.1.1 with SQL extension version 2.1.0. It is the maintained PGXN continuation of the original patchsoft project. It retains the compact UK postcode and delivery-point-suffix dps types and adds the 64-bit international postal_code type. The country-qualified text form distinguishes otherwise ambiguous national codes.
Core Workflow
Operational Boundaries
postcode supports formatting, validation and B-tree indexing. Its % prefix filter can use planner support for constant fragments; range_lower and range_upper express explicit indexed bounds. Earlier 1.3.0 incorrectly registered prefix matching as B-tree equality, and the maintained series fixes that as well as a heap-overflow defect. Replace the library and run ALTER EXTENSION postcode UPDATE; merely replacing binaries does not repair SQL operator metadata.
For international values, postal_code requires a country code, such as the examples above. country extracts it; postal_prefix, lower_bound and upper_bound support prefixes. is_valid_postal_code and to_postal_code help ingest dirty input, and a country typmod can constrain a column. Format validation is not proof of allocation or address existence.
Upstream CI tests PostgreSQL 14–18. The Pigsty packages also pass the regression suite on PostgreSQL 19 with a build compatibility patch. Installation is superuser-only, the extension is relocatable and no preload is required. Existing UK types and stored values are retained by the additive 2.0 upgrade.
Version 2.1.0 adds part, parts and prefix_of to both postal types. Cast string literals explicitly because those overloads are ambiguous for untyped text. postal_code_parts lists available names. to_char(postcode, text) is deprecated but remains in 2.x. This release also fixes a use-after-free when compiling very large custom patterns; built-in patterns are not affected. Run ALTER EXTENSION postcode UPDATE after installing the new library; the 2.1 upgrade preserves existing stored values.