-- StreetAddress:DirectionPrefixAbbreviation:StreetName:StreetTypeAbbreviation:
-- DirectionSuffixAbbreviation:Location:StateAbbreviation:ZipCode
-- This is more standardized and better for use with a geocoder.
-CREATE OR REPLACE FUNCTION normalize_address(
- in_rawInput VARCHAR
-) RETURNS norm_addy
-AS $_$
+CREATE OR REPLACE FUNCTION normalize_address(in_rawinput character varying)
+ RETURNS norm_addy AS
+$$
DECLARE
debug_flag boolean := false;
result norm_addy;
ws := E'[ ,.\t\n\f\r]';
IF debug_flag THEN
- raise notice 'input: %', rawInput;
+ raise notice '% input: %', clock_timestamp(), rawInput;
END IF;
-- Assume that the address begins with a digit, and extract it from
addressString := substring(rawInput from '^([0-9].*?)[ ,/.]');
IF debug_flag THEN
- raise notice 'addressString: %', addressString;
+ raise notice '% addressString: %', clock_timestamp(), addressString;
END IF;
-- There are two formats for zip code, the normal 5 digit, and
END IF;
IF debug_flag THEN
- raise notice 'zipString: %', zipString;
+ raise notice '% zipString: %', clock_timestamp(), zipString;
END IF;
IF zipString IS NOT NULL THEN
END IF;
IF debug_flag THEN
- raise notice 'fullStreet: %', fullStreet;
+ raise notice '% fullStreet: %', clock_timestamp(), fullStreet;
END IF;
-- FIXME: state_extract should probably be returning a record so we can
END IF;
IF debug_flag THEN
- raise notice 'stateAbbrev: %', result.stateAbbrev;
+ raise notice '% stateAbbrev: %', clock_timestamp(), result.stateAbbrev;
END IF;
-- The easiest case is if the address is comma delimited. There are some
END IF;
IF debug_flag THEN
- raise notice 'fullStreet: %', fullStreet;
- raise notice 'location: %', result.location;
+ raise notice '% fullStreet: %', clock_timestamp(), fullStreet;
+ raise notice '% location: %', clock_timestamp(), result.location;
END IF;
-- Pull out the full street information, defined as everything between the
END IF;
IF debug_flag THEN
- raise notice 'fullStreet: %', fullStreet;
+ raise notice '% fullStreet: %', clock_timestamp(),fullStreet;
END IF;
+ IF debug_flag THEN
+ raise notice '% start location extract', clock_timestamp();
+ END IF;
result.location := location_extract(fullStreet, result.stateAbbrev);
+ IF debug_flag THEN
+ raise notice '% end location extract', clock_timestamp();
+ END IF;
+
-- A location can't be a street type, sorry.
IF lower(result.location) IN (SELECT lower(name) FROM street_type_lookup) THEN
result.location := NULL;
END IF;
IF debug_flag THEN
- raise notice 'streetTypeAbbrev: %', result.streetTypeAbbrev;
+ raise notice '% streetTypeAbbrev: %', clock_timestamp(), result.streetTypeAbbrev;
END IF;
-- There is a little more processing required now. If the word after the
result.parsed := TRUE;
RETURN result;
END
-$_$ LANGUAGE plpgsql;
+$$
+ LANGUAGE plpgsql STABLE
+ COST 100;