Last active
August 29, 2015 14:07
-
-
Save simonewebdesign/f145078ad157ba5b36c8 to your computer and use it in GitHub Desktop.
PostgreSQL regexp_replace example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION isFoo(text) RETURNS BOOLEAN AS ' | |
SELECT $1 ~* ''insert_regex_here'' AS RESULT | |
' LANGUAGE SQL; | |
UPDATE blocks | |
SET content=(SELECT regexp_replace(content, 'insert_regex_here', 'insert_replace_text_here')); | |
;--WHERE isFoo(content); | |
SELECT * | |
FROM blocks | |
WHERE isFoo(content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
UPDATE
should replace every occurrence of URLs like//../../../foo/whatever
with a forward slash.We'll have to execute that SQL query at least 4 times because it's actually replacing only the first occurrence of the regex match.