Skip to content

codesystem

Hierarchical classification code types with validation and revision tracking

codesystem · Hierarchical classification code types with validation and revision tracking

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3540codesystemcodesystem0.2.0TYPEBSD-2-ClauseC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno
Distribution 0.2.1 keeps SQL/control 0.2.0; no extension upgrade from 0.2.0 is needed. Optional GSS entity updates and publisher-fetched ISIC/ISCO loaders need plpython3u, superuser installation and network access. Core extension dependencies unchanged. Upstream CI covers PG13-17; local EL9 aarch64 builds and regression checks additionally validate PG18.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.2.019 18 17 16 15codesystem-
RPMPIGSTY0.2.119 18 17 16 15codesystem_$v-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
el8.aarch64N/APIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
el9.x86_64PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
el9.aarch64PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
el10.x86_64PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
el10.aarch64PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1PIGSTY 0.2.1
d12.x86_64N/AN/AN/AN/AN/A
d12.aarch64N/AN/AN/AN/AN/A
d13.x86_64N/AN/AN/AN/AN/A
d13.aarch64N/AN/AN/AN/AN/A
u22.x86_64N/AN/AN/AN/AN/A
u22.aarch64N/AN/AN/AN/AN/A
u24.x86_64N/AN/AN/AN/AN/A
u24.aarch64N/AN/AN/AN/AN/A
u26.x86_64N/AN/AN/AN/AN/A
u26.aarch64N/AN/AN/AN/AN/A
PackageVersionOSORGSIZEFile URL
codesystem_190.2.1el9.x86_64pigsty122.9 KiBcodesystem_19-0.2.1-1PGSTY.el9.x86_64.rpm
codesystem_190.2.1el9.aarch64pigsty122.0 KiBcodesystem_19-0.2.1-1PGSTY.el9.aarch64.rpm
codesystem_190.2.1el10.x86_64pigsty123.7 KiBcodesystem_19-0.2.1-1PGSTY.el10.x86_64.rpm
codesystem_190.2.1el10.aarch64pigsty123.0 KiBcodesystem_19-0.2.1-1PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
codesystem_180.2.1el8.x86_64pigsty123.2 KiBcodesystem_18-0.2.1-1PGSTY.el8.x86_64.rpm
codesystem_180.2.1el8.aarch64pigsty120.7 KiBcodesystem_18-0.2.1-1PGSTY.el8.aarch64.rpm
codesystem_180.2.1el9.x86_64pigsty123.0 KiBcodesystem_18-0.2.1-1PGSTY.el9.x86_64.rpm
codesystem_180.2.1el9.aarch64pigsty122.0 KiBcodesystem_18-0.2.1-1PGSTY.el9.aarch64.rpm
codesystem_180.2.1el10.x86_64pigsty123.6 KiBcodesystem_18-0.2.1-1PGSTY.el10.x86_64.rpm
codesystem_180.2.1el10.aarch64pigsty123.0 KiBcodesystem_18-0.2.1-1PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
codesystem_170.2.1el8.x86_64pigsty123.1 KiBcodesystem_17-0.2.1-1PGSTY.el8.x86_64.rpm
codesystem_170.2.1el8.aarch64pigsty120.7 KiBcodesystem_17-0.2.1-1PGSTY.el8.aarch64.rpm
codesystem_170.2.1el9.x86_64pigsty122.9 KiBcodesystem_17-0.2.1-1PGSTY.el9.x86_64.rpm
codesystem_170.2.1el9.aarch64pigsty122.0 KiBcodesystem_17-0.2.1-1PGSTY.el9.aarch64.rpm
codesystem_170.2.1el10.x86_64pigsty123.7 KiBcodesystem_17-0.2.1-1PGSTY.el10.x86_64.rpm
codesystem_170.2.1el10.aarch64pigsty123.1 KiBcodesystem_17-0.2.1-1PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
codesystem_160.2.1el8.x86_64pigsty123.1 KiBcodesystem_16-0.2.1-1PGSTY.el8.x86_64.rpm
codesystem_160.2.1el8.aarch64pigsty120.6 KiBcodesystem_16-0.2.1-1PGSTY.el8.aarch64.rpm
codesystem_160.2.1el9.x86_64pigsty122.9 KiBcodesystem_16-0.2.1-1PGSTY.el9.x86_64.rpm
codesystem_160.2.1el9.aarch64pigsty122.0 KiBcodesystem_16-0.2.1-1PGSTY.el9.aarch64.rpm
codesystem_160.2.1el10.x86_64pigsty123.6 KiBcodesystem_16-0.2.1-1PGSTY.el10.x86_64.rpm
codesystem_160.2.1el10.aarch64pigsty123.0 KiBcodesystem_16-0.2.1-1PGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
codesystem_150.2.1el8.x86_64pigsty123.5 KiBcodesystem_15-0.2.1-1PGSTY.el8.x86_64.rpm
codesystem_150.2.1el8.aarch64pigsty120.9 KiBcodesystem_15-0.2.1-1PGSTY.el8.aarch64.rpm
codesystem_150.2.1el9.x86_64pigsty124.6 KiBcodesystem_15-0.2.1-1PGSTY.el9.x86_64.rpm
codesystem_150.2.1el9.aarch64pigsty123.3 KiBcodesystem_15-0.2.1-1PGSTY.el9.aarch64.rpm
codesystem_150.2.1el10.x86_64pigsty125.4 KiBcodesystem_15-0.2.1-1PGSTY.el10.x86_64.rpm
codesystem_150.2.1el10.aarch64pigsty124.6 KiBcodesystem_15-0.2.1-1PGSTY.el10.aarch64.rpm

Source

github.com/John-Cameron-Burns/pg-codesystem

pig build pkg codesystem;		# build rpm

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install codesystem;		# install by package name

pig install codesystem -v 19;   # install for PG 19
pig install codesystem -v 18;   # install for PG 18
pig install codesystem -v 17;   # install for PG 17
pig install codesystem -v 16;   # install for PG 16
pig install codesystem -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION codesystem;

Usage

Sources:

codesystem stores named classification systems and typed code values. Version 0.2.0 supports list hierarchies, revisions, derived standards, crosswalks and pattern-defined identifiers. A pattern validates syntax, not whether an identifier has actually been issued.

Core Workflow

CREATE EXTENSION codesystem;
CREATE TABLE classification_source (code text, level text, parent text, label text);
INSERT INTO classification_source VALUES ('A', 'section', '', 'Agriculture');
SELECT define_code_system(
  'toy',
  '[{"name":"section","width":1,"charset":"[A-Z]","link":"none","expected":1}]',
  'SELECT * FROM classification_source', 'Toy classification', 'Example');
SELECT name, current_revision, ncodes FROM code_systems;
SELECT code_label('toy:A'::code);
SELECT define_code_system_pattern('my_id', 'AA-NNN');
SELECT code_from('AB-123', 'my_id');

Operational Boundaries

Upstream CI targets PostgreSQL 13–17. Install this native extension as an administrator. Run ALTER EXTENSION codesystem UPDATE only when the SQL extension version changes. Distribution 0.2.1 still uses SQL/control version 0.2.0, so an existing 0.2.0 database needs no extension upgrade.

define_code_system validates levels and the input query’s code, level, parent and label columns. SQL literals include a system prefix; code_from converts external text. code_level, code_parent, code_ancestor, code_children and code_label expose the hierarchy. Equal text in different revisions represents different values; code_current converts to the current revision when the code remains valid.

define_code_system also accepts refines and shared_levels for derived classifications, queried through code_rollup. define_crosswalk registers correspondence pairs; code_map can return multiple matches, while code_map_unique requires exactly one. define_code_system_pattern defines bounded templates or regular expressions; code_part and code_parts return named parts. code_from_padded handles lost leading zeros, and code_first_with_prefix plus code_last_with_prefix provide indexable prefix bounds. A system cannot switch between list and pattern forms.

Registry structural edits are protected; define a new revision when accepted values change. Registry writes need appropriate table permissions, and readers need SELECT on registry tables. Custom-format restores require the upstream tools/restore.sh helper to restore registry data before typed table values. Ordinary restore ordering can fail.

Optional Classification Data Tools

Distribution 0.2.1 includes GSS code patterns and entity-type data. After separately loading tools/gss_update.sql, gss_update_entity_types() updates entity types from ONS. Loading tools/install_isic_isco.sql provides codesystem_install_isic_rev4() and codesystem_install_isco_08(), which download classifications from the UN and ILO. These helpers require an existing plpython3u, superuser installation and database-server access to the corresponding sources. They are not dependencies of the core extension.

Use dry_run to inspect fetched data first, and connect to the primary when writing the classification registry. ISIC/ISCO data is not redistributed in the package and remains subject to publisher terms. Upstream NOTICE records attribution and licensing for other bundled data.

Table reader