Postgres update with replace I am doing  select which is:

SELECT replace(field_1, E'&lt;div class="ad-content"&gt;&lt;div class="ad-title"&gt;publicidade&lt;/div&gt;&lt;div id=\'div-gpt-ad-1426519214388-1\'&gt; &lt;script type=\'text/javascript\'&gt;googletag.cmd.push(function(){googletag.display(\'div-gpt-ad-1426519214388-1\');});&lt;/script&gt; &lt;/div&gt;&lt;/div&gt;', '') FROM test


An that returns what I want, but when I try to update doing the same thing, It doesn't work as expected:

UPDATE test SET field_1 = replace(field_1, E'&lt;div class="ad-content"&gt;&lt;div class="ad-title"&gt;publicidade&lt;/div&gt;&lt;div id=\'div-gpt-ad-1426519214388-1\'&gt; &lt;script type=\'text/javascript\'&gt;googletag.cmd.push(function(){googletag.display(\'div-gpt-ad-1426519214388-1\');});&lt;/script&gt; &lt;/div&gt;&lt;/div&gt;', '')


It doesn't update the column without the 

&lt;div class="ad-content"&gt;&lt;div class="ad-title"&gt;publicidade&lt;/div&gt;&lt;div id=\'div-gpt-ad-1426519214388-1\'&gt; &lt;script type=\'text/javascript\'&gt;googletag.cmd.push(function(){googletag.display(\'div-gpt-ad-1426519214388-1\');});&lt;/script&gt; &lt;/div&gt;&lt;/div&gt;
If the SELECT works as expected, so should your UPDATE. More: it should update all columns, which is most probably not what you want.

UPDATE test
SET    field_1 = replace(field_1, $$&lt;div class="ad-content"&gt;&lt;div class="ad-title"&gt;publicidade&lt;/div&gt;&lt;div id='div-gpt-ad-1426519214388-1'&gt; &lt;script type='text/javascript'&gt;googletag.cmd.push(function(){googletag.display('div-gpt-ad-1426519214388-1');});&lt;/script&gt; &lt;/div&gt;&lt;/div&gt;$$, '')
WHERE  field_1              LIKE $$%&lt;div class="ad-content"&gt;&lt;div class="ad-title"&gt;publicidade&lt;/div&gt;&lt;div id='div-gpt-ad-1426519214388-1'&gt; &lt;script type='text/javascript'&gt;googletag.cmd.push(function(){googletag.display('div-gpt-ad-1426519214388-1');});&lt;/script&gt; &lt;/div&gt;&lt;/div&gt;%$$


I added a WHERE clause to avoid expensive and pointless empty updates.

Related:


Insert text with single quotes in PostgreSQL
How do I (or can I) SELECT DISTINCT on multiple columns?