I have a lot of rows with city and direction fields. But from an old import, city and direction are mixed in direction field. Like:
dir number, extra data, CITY, AL 111111 dir number, CITY, AL 111111 number, dir, number, CITY, dir number, CITY, AL 111111
The important thing is that 'CITY' always comes before a US postal code and I want to extract it and save it in city field with an UPDATE (using regex?). Is it possible?
Something like:
update TABLE set city = SOME_REGEX_MAGIC_FROM_DIRECTION_FIELD
where direccion ~ 'REGEX_MAGIC'
The working SQL statement:
update TABLE
set city = substring(direction FROM '([^,]+),[^,]+$')
where direction like '%, __ _____';