Parse, validate, format, and group Nigeria's NIPOST digital postcode (NDAPS)
Maintainer(s):
Adeniyikayodee
Installing and Loading
INSTALL ng_postcode FROM community;
LOAD ng_postcode;
Example
SELECT ng_postcode_parse('ek 01 a03 fk 01') AS code,
ng_postcode_format(ng_postcode_truncate('ek 01 a03 fk 01', 'district')) AS district;
About ng_postcode
Nigeria's digital postcode has eleven letters and digits in five segments: state, local government area, district, area, and unit. It is written EK-01-A03-FK-01 and stored as EK01A03FK01.
This extension reads the code offline, with no network call and no lookup table. A value that is not a well-formed code gives NULL.
ng_postcode_parse(text)returns the compact form of a complete code.ng_postcode_prefix_parse(text)accepts a code cut off after any segment.ng_postcode_format(text)returns the hyphenated form.ng_postcode_truncate(text, segment)cuts a code afterstate,lga,district,area, orunit.ng_postcode_parent(text)returns the next coarser prefix.ng_postcode_within(text, prefix)tells whether a code lies inside a prefix.ng_postcode_compact(text)strips spaces and hyphens and uppercases.ng_postcode_version()returns the extension version.
Counting rows by district needs no map:
SELECT ng_postcode_format(ng_postcode_truncate(postcode, 'district')) AS district, count(*)
FROM deliveries GROUP BY 1 ORDER BY 2 DESC;
The functions pass the shared test cases of the ng-postcode libraries for Rust, Python, JavaScript, and Java. The source is at https://github.com/Adeniyikayodee/ng-postcode-duckdb.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| ng_postcode_compact | scalar | NULL | NULL | |
| ng_postcode_format | scalar | NULL | NULL | |
| ng_postcode_parent | scalar | NULL | NULL | |
| ng_postcode_parse | scalar | NULL | NULL | |
| ng_postcode_prefix_parse | scalar | NULL | NULL | |
| ng_postcode_truncate | scalar | NULL | NULL | |
| ng_postcode_version | scalar | NULL | NULL | |
| ng_postcode_within | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
This extension does not add any settings.