Search code examples
stringpostgresqldspace

Reverting an addition to a string in PostrgreSQL


I followed the steps in this question Append text to column data based on the column in PostgreSQL But I made a mistake in the SIMILAR TO clause and the text got added to fields it shouldn't have. How can I reverse it?

Te query I ran was:

update metadatavalue set text_value = 'Fil: ' || text_value where metadata_field_id = 136 and text_value not similar to 'Fill:%';

How can I remove extre characters from those fields?

Thanks a lot in advance.


Solution

  • You can trim the prepended string off and update the column with the result:

    UPDATE metadatavalue
    SET text_value = regexp_replace(text_value, '^Fil: ','');