Home > Net >  replacing the part of the file path in postgresql
replacing the part of the file path in postgresql

Time:09-21

I have a column called path containing 1000 rows of the file's path, such as :

\home\me\Desktop\analysis\rep139\android-arabic-reader\AndroidManifest.xml

. . I want to replace the first six parts of this file's path "\home\me\Desktop\analysis\rep139\android-arabic-reader" with a different one and keep the remaining. I am using PostgreSQL

CodePudding user response:

Assuming the replacement be the same for all paths, say \a\b\c\d\e\f\, you may use REGEXP_REPLACE() here:

UPDATE yourTable
SET path = REGEXP_REPLACE(path, '\\.*?\\.*?\\.*?\\.*?\\.*?\\.*?\\', '\a\b\c\d\e\f\');
  • Related