I'm attempting to write a sql script in postgres. I have two columns: Column A and Column B. Both columns are strings. Column B represents a prefix which was appended to Column A (if B wasn't null). Example: If Column B had "PA" and the value to be added to Column A was "102", then Column A will now contain "PA102." I want to update a new Column C with the value of Column A without the prefix.
I was attempting to use the following:
regexp_replace(COLUMN_A, COLUMN_B, '')
The documentation for regexp_replace (below) says:
"If the pattern does not match, the function returns no rows."
I need for the method to return the whole string from Column A if Column B doesn't match. Is there some other method (or maybe a flag for regexp_replace) which would accomplish this?
Thanks in advance.
regexp_replace docs:
http://www.postgresql.org/docs/9.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP