mirror of
https://github.com/openmaptiles/openmaptiles.git
synced 2025-12-08 18:02:18 +00:00
This PR collapses housenumber values into the form min(housenumber)-max(housenumber) for cases where housenumber is a semi-colon separated list. If the list is all numbers, the bounds are the smallest and largest numbers. If the list includes non-numeric characters, it falls back to the first and last values in the list.
21 lines
836 B
PL/PgSQL
21 lines
836 B
PL/PgSQL
CREATE OR REPLACE FUNCTION display_housenumber_nonnumeric(raw_housenumber text)
|
||
RETURNS text AS $$
|
||
-- Find the position of the semicolon in the input string
|
||
-- and extract the first and last value
|
||
SELECT substring(raw_housenumber from 1 for position(';' in raw_housenumber) - 1)
|
||
|| '–'
|
||
|| substring(raw_housenumber from position(';' in raw_housenumber) + 1);
|
||
$$ LANGUAGE SQL IMMUTABLE;
|
||
|
||
|
||
CREATE OR REPLACE FUNCTION display_housenumber(raw_housenumber text)
|
||
RETURNS text AS $$
|
||
SELECT CASE
|
||
WHEN raw_housenumber !~ ';' THEN raw_housenumber
|
||
WHEN raw_housenumber ~ '[^0-9;]' THEN display_housenumber_nonnumeric(raw_housenumber)
|
||
ELSE
|
||
(SELECT min(value)::text || '–' || max(value)::text
|
||
FROM unnest(string_to_array(raw_housenumber, ';')::int[]) AS value)
|
||
END
|
||
$$ LANGUAGE SQL IMMUTABLE;
|