Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably want to use <a href="http://www.postgresql.org/docs/current/static/functions-string.html" rel="nofollow"><code>replace</code></a>:</p> <pre><code>SELECT REPLACE(text, '"', E'\\"') FROM aTable WHERE ... </code></pre> <p>You'll need to escape your escape character to get a literal backslash (hence the doubled backslash) and use the "E" prefix on the replacement string to get the right <a href="http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE" rel="nofollow">escape syntax</a>.</p> <p><strong>UPDATE</strong>: And thanks to a_horse_with_no_name's usual strictness (a good thing BTW), we have a solution that doesn't need the extra backslash or non-standard "E" prefix:</p> <pre><code>set standard_conforming_strings = on; SELECT REPLACE(text, '"', '\"') FROM aTable WHERE ... </code></pre> <p>The <a href="http://www.postgresql.org/docs/current/static/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS" rel="nofollow"><code>standard_conforming_strings</code></a> option tells PostgreSQL to use standard syntax for SQL strings:</p> <blockquote> <p>This controls whether ordinary string literals ('...') treat backslashes literally, as specified in the SQL standard.</p> </blockquote> <p>This would also impact your <a href="http://www.postgresql.org/docs/9.0/interactive/sql-syntax-lexical.html#SQL-BACKSLASH-TABLE" rel="nofollow"><code>\x5C</code> escape</a>:</p> <blockquote> <p>If the configuration parameter standard_conforming_strings is off, then PostgreSQL recognizes backslash escapes in both regular and escape string constants. This is for backward compatibility with the historical behavior, where backslash escapes were always recognized.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload