title: Escaping Backslashes in Postgresql
body: <p>I need to write a file to disk from postgres that has character string of a backslash immediately followed by a forward slash <code>\/</code></p>
  
  <p>Code similar to this has not worked:</p>
  
  <pre><code>drop table if exists test;
  create temporary table test (linetext text);
  insert into test values ('\/\/foo foo foo\/bar\/bar');
  copy (select linetext from test) to '/filepath/postproductionscript.sh';
  </code></pre>
  
  <p>The above code yields <code>\\/\\/foo foo foo\\/bar\\/bar</code> ... it inserts an extra backslash. </p>
  
  <p>When you view the temp table, the string is correctly viewed as <code>\/\/</code>, so I am not sure where or when the text is changed into <code>\\/\\/</code></p>
  
  <p>I've tried doubling the <code>\</code>, variations of E before the string, and quote_literal() without luck.</p>
  
  <p>I have note found a solution here <a href="http://www.postgresql.org/docs/9.2/interactive/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-UESCAPE" rel="nofollow">Postgres Manual</a></p>
  
  <p>Running Postgres 9.2, encoded UTF-8.</p>