when parsing state from city, anchor pattern on right
authorGalen Charlton <gmc@esilibrary.com>
Fri, 8 Mar 2013 18:20:47 +0000 (13:20 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 8 Mar 2013 18:20:47 +0000 (13:20 -0500)
This avoids "ANCHOR POINT AK" from becoming {"ANCHORINT", "AK"}

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

sql/base/base.sql

index e18c004..751ce72 100644 (file)
@@ -365,9 +365,9 @@ CREATE OR REPLACE FUNCTION migration_tools.address_parse_out_citystatezip (TEXT)
             state := REGEXP_REPLACE( city_state_zip, E'^(.*),(.*)$', E'\\2');
             city := REGEXP_REPLACE( city_state_zip, E'^(.*),(.*)$', E'\\1');
         ELSE
-            IF city_state_zip ~ E'\\s+[A-Z][A-Z]\\s*' THEN
-                state := REGEXP_REPLACE( city_state_zip, E'^.*,?\\s+([A-Z][A-Z])\\s*.*$', E'\\1' );
-                city := REGEXP_REPLACE( city_state_zip, E'^(.*?),?\\s+[A-Z][A-Z](\\s*.*)$', E'\\1\\2' );
+            IF city_state_zip ~ E'\\s+[A-Z][A-Z]\\s*$' THEN
+                state := REGEXP_REPLACE( city_state_zip, E'^.*,?\\s+([A-Z][A-Z])\\s*$', E'\\1' );
+                city := REGEXP_REPLACE( city_state_zip, E'^(.*?),?\\s+[A-Z][A-Z](\\s*)$', E'\\1\\2' );
             ELSE
                 IF city_state_zip ~ E'^\\S+$'  THEN
                     city := city_state_zip;