Create Postal Addresses View
CREATE OR REPLACE VIEW addressbase.postal_addresses AS
SELECT formatted_address.uprn, formatted_address.rm_udprn, formatted_address.rpc, (initcap(((ltrim(formatted_address.saon || formatted_address.paon) || formatted_address.street_description) || ', '::text) || formatted_address.localitytown) || ' '::text) || formatted_address.postcode::text AS full_address, formatted_address.postcode, formatted_address.geom
FROM ( SELECT addressbase.uprn, addressbase.rm_udprn, addressbase.rpc, addressbase.geom, btrim((
CASE
WHEN addressbase.organisation_name IS NOT NULL THEN addressbase.organisation_name::text || ', '::text
ELSE ''::text
END ||
CASE
WHEN addressbase.sub_building_name IS NOT NULL THEN addressbase.sub_building_name::text || ', '::text
ELSE ''::text
END) ||
CASE
WHEN addressbase.building_name IS NOT NULL THEN addressbase.building_name::text || ', '::text
ELSE ''::text
END) || ' '::text AS saon, ltrim(
CASE
WHEN addressbase.building_number IS NOT NULL THEN addressbase.building_number::text
ELSE ''::text
END ||
CASE
WHEN addressbase.dependent_thoroughfare_name IS NOT NULL THEN (' '::text || addressbase.dependent_thoroughfare_name::text) || ', '::text
ELSE ' '::text
END) AS paon,
CASE
WHEN addressbase.throughfare_name IS NOT NULL THEN addressbase.throughfare_name::text
ELSE ''::text
END AS street_description,
CASE
WHEN addressbase.dependent_locality IS NOT NULL THEN addressbase.dependent_locality::text || ', '::text
ELSE ''::text
END ||
CASE
WHEN addressbase.post_town IS NOT NULL THEN addressbase.post_town::text
ELSE ''::text
END AS localitytown, addressbase.postcode
FROM addressbase.addressbase) formatted_address;
Updated less than a minute ago