Skip to content

feat(sql): add the postcode as a PostgreSQL domain and DuckDB macros - #75

Merged
Adeniyikayodee merged 3 commits into
mainfrom
feat/sql
Oct 10, 2026
Merged

Adeniyikayodee merged 3 commits into
mainfrom
feat/sql

Conversation

@Adeniyikayodee

Copy link
Copy Markdown
Owner

The postcode as a column type, in plain SQL. There is no extension to build, so both files load on managed services that accept none.

  • PostgreSQL (sql/postgres.sql): an ng_postcode domain that refuses anything but a compact code, an ng_postcode_prefix domain, and six immutable functions: parse a code or a prefix, format, truncate to a segment, parent, and within.
  • DuckDB (sql/duckdb.sql): macros with the same names and answers. DuckDB has no domains, so the README gives the constraint to use.
  • Same answers as the libraries: scripts/sql_conformance.py turns the cases in spec/vectors.json into SQL and runs them, 101 on each engine. Two steps in the python job run it, so the ruleset is unchanged.
  • Locale: the SQL uses translate() because upper() follows the database locale. I ran PostgreSQL 17 under a Turkish locale, where a naive version would mishandle i, along with PostgreSQL 14 and DuckDB 1.5.
  • Index use: selecting a district as a range on the column uses its index; I confirmed that with EXPLAIN and the README shows the form.

One thing the README warns about because I got it wrong first: a DuckDB constraint written with = lets a malformed code through, since comparing with NULL is not false. It needs IS NOT DISTINCT FROM.

The CI steps use the runner's preinstalled PostgreSQL, which I could not exercise locally. If they fail here, I will fix them on this branch.

@Adeniyikayodee
Adeniyikayodee merged commit d2c69d8 into main Oct 10, 2026
16 checks passed
@Adeniyikayodee
Adeniyikayodee deleted the feat/sql branch October 10, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant