I need to clean up an address field in PostgreSQL 8.4 by removing everything to the right of a street name. This includes dropping suites ("100 Broadway Street Suite 100") and correcting names that have unit numbers appended to the street name ("100 Broadway Street100") so that the result in both cases would be "100 Broadway Street".
Essentially I am trying to remove everything to the right of "Street". I can't seem to get a replace function to work without individually coding for each case. A rtrim function also doesn't work because the characters I want removed would be a wildcard.
Here is what I am trying to get to work:
update *tablename* set *fieldname* = replace (*fieldname*, '%STREET%', '%STREET')
This SQL below works, but I don't want to code each possible combination:
UPDATE *tablename* set *fieldname* = replace (*fieldname*, ' SUITE 100', '');
UPDATE *tablename* set *fieldname* = replace (*fieldname*, ' STREET100', ' STREET');
How can I remove everything to the right of a string "Street" without explicitly specifying what follows "Street"?
Thanks for the help.